https://ch.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-12-16T05:00:26Ztag:ch.mathworks.com,2005:Question/3126932016-11-17T11:55:45Z2017-12-16T05:00:26ZHow can I get verification code for matlab online?<p>I need basic introduction of Matlab.</p>Janez Luzarhttps://ch.mathworks.com/matlabcentral/profile/authors/6831872-janez-luzartag:ch.mathworks.com,2005:Question/3730382017-12-15T00:21:55Z2017-12-16T04:57:24ZHow to change workspace of imageSegmenter from 'base' to 'current' to access the binary masks created by ImageSegmenter? <p>I have called imageSegmenter inside a function. I am drawing masks on images and would like to access these masks inside the same function. The masks created are in the base work space. How do I access these masks inside a function?</p>Jasmine Patilhttps://ch.mathworks.com/matlabcentral/profile/authors/7132511-jasmine-patiltag:ch.mathworks.com,2005:Question/3732322017-12-16T04:46:20Z2017-12-16T04:46:20Zhow can we use the trainingloss function to evaluate the performance of a CNN training model?<p>Hello,
i am doing a classification work using CNN network. i have built a network with 10 layers, i have used a dataset of 300 and i got an accuracy of 0.87. i would like to know how i can make use of the trainingloss function and other traininginfo to evaluate the effectiveness of my model.</p><p>thanks,</p>Patrice Monkamhttps://ch.mathworks.com/matlabcentral/profile/authors/10336138-patrice-monkamtag:ch.mathworks.com,2005:Question/3731782017-12-15T16:51:57Z2017-12-16T04:39:15Zpattern of color range of different shades of a particular colors RGB values?<p>Sir I have found the RGB value of all colors.Now I have one doubt that is there any pattern in different shades of a particular colors RGB values.I want to know the pattern that how the RGB values of different shades of a particular color are decided.I will like to explain with an example as these are different shades of blue so I want to know that how to identify these different shades of blue by a single RGB value.</p><pre class="language-matlab">Midnight Blue [25-25-112] 191970
Navy [0-0-128] 000080
Cornflower Blue [100-149-237] 6495ed
Dark Slate Blue [72-61-139] 483d8b
</pre><p>Now suppose I want to call blue color in my program, and I want that all different shades of blue should be included in that so how could I get all shades of a same color.</p><p>Apart from this sir do you have any idea that how many different colors and shades are there in a resistor.</p>AKSHAY VARSHNEYhttps://ch.mathworks.com/matlabcentral/profile/authors/10099128-akshay-varshneytag:ch.mathworks.com,2005:Question/3724192017-11-13T05:00:00Z2017-12-16T04:17:27ZWhy does MATLAB not recognize my Xcode 9 installation when running "mex -setup"?<p>Why does MATLAB report that I have "No supported compiler" when I execute "mex -setup", even though I have Xcode 9 installed on my machine and it is shown as a supported compiler on MathWorks.com?</p><p> </p><pre> >> mex -setup -v
Verbose mode is on.
... Looking for compiler 'Xcode with Clang' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'xcode-select -print-path' ...Yes ('/Library/Developer/CommandLineTools').
... Looking for folder '/Library/Developer/CommandLineTools' ...Yes.
... Executing command 'which xcrun' ...Yes ('/usr/bin/xcrun').
... Looking for folder '/usr/bin' ...Yes.
... Executing command 'defaults read com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...No.
... Executing command 'defaults read /Library/Preferences/com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...Yes ('9.0').
... Executing command '
agreed=9.0
if echo $agreed | grep -E '[\.\"]' >/dev/null; then
lhs=`expr "$agreed" : '\([0-9]*\)[\.].*'`
rhs=`expr "$agreed" : '[0-9]*[\.]\(.*\)$'`
if echo $rhs | grep -E '[\."]' >/dev/null; then
rhs=`expr "$rhs" : '\([0-9]*\)[\.].*'`
fi
if [ $lhs -gt 4 ] || ( [ $lhs -eq 4 ] && [ $rhs -ge 3 ] ); then
echo $agreed
else
exit 1
fi
fi' ...Yes ('9.0').
... Executing command 'xcrun -sdk macosx --show-sdk-path' ...No.
Did not find installed compiler 'Xcode with Clang'.
Error using mex
No supported compiler or SDK was found. For options, visit
<https://www.mathworks.com/support/compilers>.</pre><p> </p>MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ch.mathworks.com,2005:Question/3351622017-04-13T07:07:56Z2017-12-16T04:14:13ZReport a bug of R2017a on MacBook Pro 2016, java.lang.reflect.InvocationTargetException<p>Hi,
I use MacBook Pro 2016 with <i>Japanese Keyboard Layout</i>.</p><p>I have installed MATLAB R2017a on macOS Sierra 10.12.4.</p><img src = "/matlabcentral/answers/uploaded_files/75013/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-04-13%20%E4%B8%8B%E5%8D%884.04.21.png"><img src = "/matlabcentral/answers/uploaded_files/88337/file.png"><p>Following red error messages will appear in Command Window sometimes.</p><pre class="language-matlab">java.lang.reflect.InvocationTargetException
at sun.lwawt.macosx.LWCToolkit.invokeAndWait(LWCToolkit.java:572)
at sun.lwawt.macosx.CInputMethod.attributedSubstringFromRange(CInputMethod.java:586)
Caused by: java.lang.IllegalArgumentException: Invalid range
at javax.swing.text.JTextComponent$InputMethodRequestsHandler.getCommittedText(JTextComponent.java:4595)
at sun.awt.im.InputMethodContext.getCommittedText(InputMethodContext.java:302)
at sun.lwawt.macosx.CInputMethod$3.run(CInputMethod.java:598)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:302)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:738)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:699)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:713)
at java.awt.EventQueue$4.run(EventQueue.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:710)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
</pre><p>There was a thread reported this bug. She gave a method to solve the problem, but I think she haven't solved the problem because I tried her method and it doesn't work well.</p><p><a href = "https://jp.mathworks.com/matlabcentral/answers/332990-error-starting-desktop-r2017a-on-mac-os-sierra-solved">Error starting desktop r2017a on mac os Sierra (Solved)</a></p><p>I think I find something useful for fixing the bug.</p><p>This bug was caused by Chinese Input Method. I installed Chinese Input Method into a MacBook Pro <i>(2016)</i> with <i>Japanese Keyboard Layout</i>. After running a script, if I clicked command window <i>immediately</i> under Chinese Input Method, the error messages will appear.</p><p>Temporary Solution：</p><p><i>After running a script, before clicking the command window</i>,</p><p>change your input method to any other input methods if your current method is Chinese;</p><p><i>or</i> click one of the other window blocks first, such as workspace.</p><p>I hope this bug can be fixed as soon as possible.</p><p>Thank you.</p>Junhttps://ch.mathworks.com/matlabcentral/profile/authors/2551510-juntag:ch.mathworks.com,2005:Question/3462612017-06-26T11:29:00Z2017-12-16T04:11:14ZWhy can't MEX find a supported compiler in MATLAB R2017a in macOS Sierra<p>I'm using the latest macOS (Sierra 10.12.5) and mex can not find the compiler, or SDK even if the latest Xcode (8.3.3) and Intel Paralell Studio are installed.</p>Peter Kerekeshttps://ch.mathworks.com/matlabcentral/profile/authors/10071291-peter-kerekestag:ch.mathworks.com,2005:Question/3732202017-12-16T00:36:29Z2017-12-16T04:06:42ZHow to calculate the following complex integration <p>I want to integrate something similar to the following:</p><pre> int_0^inf(exp(c*int_z^inf(1- int_0^inf(1/(x*y) dx))*ydy))dz</pre><p>I tried the following:</p><pre class="language-matlab">syms x y z
</pre><pre class="language-matlab">g = int(1/(x*y),x,0,inf);
</pre><pre class="language-matlab">f = int((1-g)*y,y,z,inf);
</pre><pre class="language-matlab">f = @(x,y,z) exp(c*f);
</pre><pre class="language-matlab">h = integral(@(z) f(x,y,z) , 0,inf)
</pre><p>but I get the following error:</p><pre class="language-matlab">Error using integralCalc/finalInputChecks (line 511)
</pre><pre class="language-matlab">Input function must return 'double' or 'single' values. Found 'sym'.
</pre><pre class="language-matlab">Error in integralCalc/iterateScalarValued (line 315)
</pre><pre> finalInputChecks(x,fx);</pre><pre class="language-matlab">Error in integralCalc/vadapt (line 132)
</pre><pre> [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);</pre><pre class="language-matlab">Error in integralCalc (line 83)
</pre><pre> [q,errbnd] = vadapt(@AToInfInvTransform,interval);</pre><pre class="language-matlab">Error in integral (line 88)
</pre><pre class="language-matlab">Q = integralCalc(fun,a,b,opstruct);
</pre>Heshamhttps://ch.mathworks.com/matlabcentral/profile/authors/3365667-heshamtag:ch.mathworks.com,2005:Question/3730332017-12-14T23:27:21Z2017-12-16T04:03:07ZHas anyone ever thought about using 2 complex planes: Ax+Bi+Ci' ?<p>Is a reason NOT to graph a 3-D figure with x-axis of REAL numbers, y-axis of IMAGINARY numbers marked off as i, and the z-axis as the second IMAGINARY axis -- marked of as i-prime? I am convinced that it is a viable approach and my results are revealing interesting aspects of the Mandelbrot Set. If I am crazy -- please tell me now. If I am on to an interesting concept -- please tell what Math Tool can handle those 3 planes - 1 real and 2 imaginary. I will have to build a tool -- if one does not exist (or I just might quit -- if I am crazy).</p>David Fashenpourhttps://ch.mathworks.com/matlabcentral/profile/authors/11709514-david-fashenpourtag:ch.mathworks.com,2005:Question/3732312017-12-16T03:54:34Z2017-12-16T03:54:34Zwhat is the function/code should i use to segment the different fruits in rgb? ty<img src = "/matlabcentral/answers/uploaded_files/98740/fruit.png">Amir Aizathttps://ch.mathworks.com/matlabcentral/profile/authors/11094692-amir-aizattag:ch.mathworks.com,2005:Question/3732232017-12-16T01:48:18Z2017-12-16T03:52:11ZHow to calculate time elapsed (time in GMT format)<p>Hi,</p><p>I have below two different times, and want to calculate time elapsed:</p><pre class="language-matlab">2017-12-13-T16:00:23.488+08:00
2017-12-13-T16:02:24.982+08:00
</pre><p>Many thanks in advance,</p>Kanakaiah Jakkulahttps://ch.mathworks.com/matlabcentral/profile/authors/6734702-kanakaiah-jakkulatag:ch.mathworks.com,2005:Question/3730122017-12-14T20:09:30Z2017-12-16T03:38:39Zwant to do optimization with fmincon but without having exact function<p>Hi,</p><p>I want to do an optimization for constrain problem and use fmincon.</p><p>The problem is that, I don't have function that be defined by variables like f(x,y)=x^2+y^2</p><p>I have FEM model which is contain a file with thousands of line in bdf format, which is as input for MSC.NASTRAN</p><p>I cloud read my design variable from that file and store them in parameters, as well as write new value on the specific place.
Then I will call MSC.Nastran to do computation and then generate f06 file, which the value of objective and constrains are stored in that and read these value and store them in parameters too.</p><p>I want to use fmincon to do optimization for my problem but it gives me error which i think this is due to calculation of gradient of function, because for 10 variables problem it do 11 calculation and then error appear.</p><p>Thanks so much in advanced.</p>mohammad haghnejathttps://ch.mathworks.com/matlabcentral/profile/authors/2338491-mohammad-haghnejattag:ch.mathworks.com,2005:Question/3728852017-12-14T06:33:55Z2017-12-16T03:26:31ZHow to extract multiple matrices from a big set (Large Matrix) of data? <p>Hello Matlab,</p><p>I need some help extracting some matrices from a bigger data set. My large 4D-matrix/ dataset has the following dimension: (5*5*14680*30). That's 30 sets of 14680 of five by five matrices. I want to extract multiple (5*5) matrices from all the 30 sets. The 5*5 matrix selection needs to be done based on the matrix location/Order, they are stacked up from 1 through 14680. For example, I want to extract the (5*5)matrices number 500, 550, 700, 755,& 793 out of the 14680 Matrices and in each set (30 sets total). I was thinking a loop and an "if" statement may do the job because I need to extract 580 matrices then 1170 of them, and I know exactly where they are located so I have a vector (580,1) containing the exact location for the matrices I need. I would greatly appreciate some feedback. Thanks</p>Amine Ben Ayara https://ch.mathworks.com/matlabcentral/profile/authors/6651884-amine-ben-ayaratag:ch.mathworks.com,2005:Question/3732242017-12-16T01:56:53Z2017-12-16T03:21:17ZCalculate elements in matrices<p>Hello
I have two matrices with the same size, I want the numbers in the first matrix A to divide the numbers in the second matrix B, and collect the result in matrix C.
For instance A=[12 6 4],B=[10 2 4], how cold I get[1.2 3 1]</p><p>Thank you</p>Pei Jiahttps://ch.mathworks.com/matlabcentral/profile/authors/11206582-pei-jiatag:ch.mathworks.com,2005:Question/3732262017-12-16T02:28:46Z2017-12-16T03:18:00ZWhy does it say Matrix dimensions must agree? How can I fix this?<pre class="language-matlab">if true
% code
end
po = 4000;
u = 1.5;
ct = 0.000012;
Bo = 1.25;
q = 300;
phi = 0.15;
k = 60;
h = 15;
Ei = 12;
r = 0:1:900;
t = 0:0.2777:25;
P= po-(((70.6*q*u*Bo)./(k*h))*(-Ei*(-1*(952.381.*phi.*u.*ct.*(r.^2)))./(k.*t)));
plot3(r,t,P);
xlabel('r');
ylabel('t');
zlabel('Pr');
title('Plot of P(r)');
</pre>Michal Pelichttps://ch.mathworks.com/matlabcentral/profile/authors/10917749-michal-pelictag:ch.mathworks.com,2005:Question/3732302017-12-16T02:53:43Z2017-12-16T02:53:43Zwhy do i receive a data type mismatch error in simulink 8.7 when i build a model<p>Hi, i am a beginner of Matlab. I met a problem with it now. I can build my "PCS contril model" in Matlab 2010b without errors. While when i build the same model in Matlab 2016b, I received the data type mismatch error. I know it is because the input data types of mux are not the same.But i wonder why it works in Matlab 2010b while not in Matlab 2016b. Is there any simple solution instead of changing all 15 input data types to the same. thanks.</p>gordon xuhttps://ch.mathworks.com/matlabcentral/profile/authors/11211743-gordon-xutag:ch.mathworks.com,2005:Question/3732292017-12-16T02:49:18Z2017-12-16T02:49:18ZHow to write a vector-valued function with vector input from the screen in MATLAB?<p>I am trying to do the following in MATLAB:</p><pre> 1. input *from screen* a small positive integer M (between 1 and 8);
2. input *from screen* M function expressions with variables `t, x1, x2, ... xM`; name for now these M functions f1,f2,...,fM;
3. given a vector `v=[t,x1,x2,...,xM]`, evaluate each of the M functions with the input `v`;
4. the output is a vector `Y=[y1,y2,...,yM]` where `y1=f1(v),y2=f2(v),...`.</pre><p>I learned from this [old code][1] that I can do (1) and (2) with</p><pre> TRUE = 1;
FALSE = 0;
OK = FALSE;
while OK == FALSE
fprintf(1,'Input the number of equations\n');
M = input(' ');
if M <= 0 | M > 7
fprintf(1,'Number must be a positive integer < 8\n');
else
OK = TRUE;
end;
end;
ss = cell(M,1);
for I = 1:M
fprintf(1,'Input the function F_(%d) in terms of t and y1 ... y%d\n', I,M);
fprintf(1,'For example: ''y1-t^2+1'' \n');
kk = input(' ');
ss{I} = kk;
end;</pre><p>How can I do (3) and (4)?</p><pre class="language-matlab">[1]: https://www.mathworks.com/matlabcentral/answers/uploaded_files/97690/ALG057.m
</pre>jackhttps://ch.mathworks.com/matlabcentral/profile/authors/2808167-jacktag:ch.mathworks.com,2005:Question/3731452017-12-15T13:55:46Z2017-12-16T02:47:43ZEffective but stingy installation of MDCS<p>If there are 3 nodes and 12 cores each, mdcs has to be installed in all 36 cores right?</p><p>Now for the nodes to communicate with each other, is installing mdcs in 1 core (or the master) of each node enough for the nodes to communicate with each other? Since we can use PCT to work with the cores within the system, we don't need to install MDCS in every core right?</p><p>This might mean a compromise on speed but is it possible?</p>Viswanath Hariharanhttps://ch.mathworks.com/matlabcentral/profile/authors/5971188-viswanath-hariharantag:ch.mathworks.com,2005:Question/3732282017-12-16T02:42:45Z2017-12-16T02:42:45Zconnect simulink block to simscape block?<p>Hi, I want to connect bipolar transistor(simscape) with branch RLC circuit (Simulink)? How ??
Please, can you help me?</p><p>Thanks in advance</p>arwahttps://ch.mathworks.com/matlabcentral/profile/authors/5116407-arwatag:ch.mathworks.com,2005:Question/3732272017-12-16T02:32:23Z2017-12-16T02:32:23ZI seem to have trouble getting my plot to show fully on the graph. I want it to be like the one shown below.. but I'm not sure how to adjust it so that it fits my gui too. Any help is appreciated!<pre> v = 2
A = 30
vx=v*cos(deg2rad(A));
vy=v*sin(deg2rad(A));
t=time_taken(vy)
h=max_height(v,A)
x=dis_travel(vx,t)
time = linspace(0, t, 1000);
legends = {}; % Instantiate an empty cell for the angle legend.
counter = 1;
for A = 10: 10 : 90
% Get the components of velocity in the x and y directions for this angle.
vx = v*cosd(A);
vy = v*sind(A);
% Assuming the object starts from ground zero
xfinal = vx * time;
yfinal = vy * time + (1/2) * 9.81 * time .^ 2;
% Clip y to zero because we assume the projectile stays on the ground when it hits.
% It does not penetrate and have a negative y.
yfinal(yfinal < 0) = 0;
indexHitGround = find(yfinal > 0, 1, 'last');
fontSize=10
plot(xfinal, yfinal, '-', 'LineWidth', 2);
hold on;
legends{end+1} = sprintf('Angle = %d', A);
% Calculate the range in the x direction.
xFinal(counter) = xfinal(indexHitGround);
counter = counter + 1;
end
grid on;
xlabel('X Coordinate', 'FontSize', fontSize);
ylabel('Y Coordinate', 'FontSize', fontSize);
title ('Projectile Trajectory', 'FontSize', fontSize)
legend(legends);
% Find the max xFinal and set the range of the graph to be that.
xlim([0, max(xFinal)]);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0.2, 0.3, 0.8, 0.7]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Projectile Trajectory Demo Part 2', 'NumberTitle', 'Off') </pre><img src = "/matlabcentral/answers/uploaded_files/98736/graph1.jpg"><img src = "/matlabcentral/answers/uploaded_files/98737/graph2.png">Kim Foohttps://ch.mathworks.com/matlabcentral/profile/authors/11759314-kim-footag:ch.mathworks.com,2005:Question/3732252017-12-16T02:12:46Z2017-12-16T02:12:46ZHow to calculate entropy for IWT image decomposition ?<p>Hi, I wanna ask. If I already perform Integer wavelet transform and I did 9 level image decomposition (I use image size 512X512). How can I calculate the entropy in each subband? what I did right now is I just use entropy function from Matlab to calculate each subband entropy but the value seems wrong, it's too small. original entropy is 7.4455, entropy for the first level is 2.7753 and for the second level is 3.3481. the entropy value is not consistent. How can I verify the entropy is true?</p>nur aqilahttps://ch.mathworks.com/matlabcentral/profile/authors/11618331-nur-aqilatag:ch.mathworks.com,2005:Question/3728002017-12-13T18:22:03Z2017-12-16T02:01:58ZHow to find minimum distance between two cylindrical objects from binary image? <p>Hello,</p><p>I have this binary image</p><img src = "/matlabcentral/answers/uploaded_files/98453/aa.jpg"><p>in which I have two cylindrical objects and I want to find out the minimum distance between these. How to do that? I have read <a href = "https://in.mathworks.com/matlabcentral/answers/274956-distance-between-two-objects">this answer</a> but I cannot understand this. Can anyone help to calculate minimum distance in a more simple way?
Thanks.</p>NASEEB SINGHhttps://ch.mathworks.com/matlabcentral/profile/authors/7431288-naseeb-singhtag:ch.mathworks.com,2005:Question/3654032017-11-06T15:24:36Z2017-12-16T01:30:38ZUSB Relay Board Numato - Sending Commands<p>Dear all,</p><p>For our experimental setups, we have been using USB relay modules from Numato and use LabView to send the commands. It works fine. I would like to implement it in Matlab for my project. While I can connect to the device, writing the command 'relay on 1', to activate the first relay, does not work.</p><p>For instance:</p><p>obj = serial('COM8');</p><p>fopen(obj);</p><p>fprintf(obj,'relay on 1');</p><p>The code works but nothing happens.
I wonder if I need to create a VISA for this, as in LabView the functions used are 'VISA write'. But if it is the case I don't know how to do it...</p><p>Thanks for your help !</p>Fabien Jammeshttps://ch.mathworks.com/matlabcentral/profile/authors/4083116-fabien-jammestag:ch.mathworks.com,2005:Question/3729832017-12-14T17:05:18Z2017-12-16T01:30:05ZOperations with tables and matrix<p>Hello,</p><p>I have three tables with some information and I want to finally obtain a 3D-matrix:</p><p>The 3 tables are:</p><img src = "/matlabcentral/answers/uploaded_files/98552/005_tables.JPG"><p>First step: I want to include information from table2 in table 1</p><img src = "/matlabcentral/answers/uploaded_files/98550/005_new_table.JPG"><p>Second step: I want to create a 3D-matrix with information from new_table1 and table 3</p><img src = "/matlabcentral/answers/uploaded_files/98551/005_matrix.JPG"><p>Any suggestions?</p><p>Thank you!</p><p>Montse</p>Montserrat Vallcorba Martíhttps://ch.mathworks.com/matlabcentral/profile/authors/11351857-montserrat-vallcorba-martitag:ch.mathworks.com,2005:Question/3732162017-12-15T23:33:55Z2017-12-16T01:19:50ZI have a 6031*6 matrix an to extract 100 random data compounds to build a 3*100 matrix.What should I do?<p>randi(100,3,A)</p>Pei Jiahttps://ch.mathworks.com/matlabcentral/profile/authors/11206582-pei-jiatag:ch.mathworks.com,2005:Question/3731442017-12-15T13:55:39Z2017-12-16T01:18:02ZHow do I find non-zero values + lonely zeros in an array?<p>Hey, I would like to find the non-zero cells plus the zeros that has no zeros before or after them.
For example in the array [0 1 2 2 2 0 0 4 5 0 3 0 0 0 5] I'll get the indexes: 1,2,3,4,5,8,9,10,11,15.</p><p>Thanks!</p>Ran Cohenhttps://ch.mathworks.com/matlabcentral/profile/authors/10122416-ran-cohentag:ch.mathworks.com,2005:Question/3732222017-12-16T01:17:00Z2017-12-16T01:17:00ZIt said undefined function when I create a new function or paste one, but when I restart MATLAB it works well. What can I do to fix this bug?<p>The problem never occured in MATLAB2016a on my compputer and now I'm puzzled by the bug using MATLAB2017b on the same computer.</p>DAR VONhttps://ch.mathworks.com/matlabcentral/profile/authors/11614085-dar-vontag:ch.mathworks.com,2005:Question/3731032017-12-15T09:41:31Z2017-12-16T01:09:03Zhow to get simulation data in the time of simulation from model when pause the system ?<p>how to get data from simulating model at paused time from matlab script and does Battery initial SOC will be set by matlab script?</p>Dinesh mallahttps://ch.mathworks.com/matlabcentral/profile/authors/7334360-dinesh-mallatag:ch.mathworks.com,2005:Question/3178632016-12-22T14:56:19Z2017-12-16T01:03:36Zdeterminant of hessian matrix of a greyscale image is too small<p>I am trying to find determinant of hessian matrix of a 50x50 grayscale image. Determinant of matrix I am getting is a very small value i.e 4.7612e-134. I think I am missing something. My code is below. Thanks</p><pre> % computing second derivatives in each direction first
[gx, gy] = gradient(double(sliceOfImageK2));
[gxx, gxy] = gradient(gx);
[gyx, gyy] = gradient(gy);</pre><pre> hessianMatrix = [gxx gxy; gxy gyy];
determinantHessianMatrix = det(hessianMatrix);</pre><p>tayyab</p>Tayyab Ateeqhttps://ch.mathworks.com/matlabcentral/profile/authors/3919169-tayyab-ateeqtag:ch.mathworks.com,2005:Question/3732072017-12-15T21:25:20Z2017-12-16T00:53:22ZBubble shape detection and creating of the mask<p>Dear Matlab community,</p><p>I am totally new in the image processing. Nevertheless, I need to <b>define the bubble</b> on image, create mask and apply the mask to the original image. If someone can help me or give any useful advice, I will be really thankful.</p><p>Issue: I have a set of images (2000 for example) at which the bubble is growing and I need to define the bubble shape at each image and apply it for the its original.</p><p>I guess that it may be really easy (or not), I just have no any idea. I've already read a number of articles which dedicated the processing issues, but still have not solved problem.</p><p>So, I attached original image and three images after some manipulations. It doesn't matter which image you can offer to process. Thanks in advance!</p><p>Original:</p><img src = "/matlabcentral/answers/uploaded_files/98721/original.png"><p>Processed_1:</p><img src = "/matlabcentral/answers/uploaded_files/98724/processed_1.png"><p>Processed_2:</p><img src = "/matlabcentral/answers/uploaded_files/98725/processed_2jpg.jpg">Alexander Bashkatovhttps://ch.mathworks.com/matlabcentral/profile/authors/6194271-alexander-bashkatovtag:ch.mathworks.com,2005:Question/3731592017-12-15T15:15:20Z2017-12-16T00:43:19Zimagesc after fft2 <p>Hello - im new in here :)</p><p>I've got some kind of radar's signal that I want to show with the imagesc() function.</p><p>After an fft2 I wanted to show my signal with:</p><pre class="language-matlab">figure; imagesc(abs(tabsygn-mean(y,2)));
</pre><p>It all worked, however when I went to reduce my axis size, something strange happened. It changed the values, however the image itself didn't change. I've used the command below:</p><pre class="language-matlab">imagesc(0:200,250:400,(abs(tabsygn-mean(y,2))));
</pre><p>The image on the left is original, and on the right is after the command above.</p><img src = "/matlabcentral/answers/uploaded_files/98682/sum.jpg">Michal Karwackihttps://ch.mathworks.com/matlabcentral/profile/authors/11757126-michal-karwackitag:ch.mathworks.com,2005:Question/3732212017-12-16T00:41:10Z2017-12-16T00:41:10ZProblem with starting parpool<p>Hello community,</p><p>I tried to run a code which worked for a 2011 version of Matlab. Initially, the code used matlabpool to pool the cores. Now I had to replace matlabpool by parpool for the newest version of Matlab. However, I get the following message error:</p><p>Caused by:
Error using parallel.internal.pool.InteractiveClient>iThrowWithCause (line 675)
Failed to start pool.
Error using parallel.Job/addClientPath (line 862)
Invalid value specified for property 'NumPathsToAppend'. Allowed values are positive integer scalars.</p><p>What am I doing wrong?</p><p>Best regards.</p>Frédéric Godinhttps://ch.mathworks.com/matlabcentral/profile/authors/11694474-frederic-godintag:ch.mathworks.com,2005:Question/3724322017-12-11T22:27:16Z2017-12-16T00:38:53ZHow to access an online movie database and output data?<p>Im trying to create a GUI/ program that extracts data from an online movie database such as : <a href = "http://www.omdbapi.com/">http://www.omdbapi.com/</a></p><p>im not sure how to write the program, or how to start. Tryin to extract simple things such as Title, director, genre, etc.</p>Carlos Oliveroshttps://ch.mathworks.com/matlabcentral/profile/authors/6034379-carlos-oliverostag:ch.mathworks.com,2005:Question/3725682017-12-12T14:33:55Z2017-12-16T00:37:59ZHow Are Calculations Done for Variable That's Inclusive of Itself?<p>Consider the following simple scenario:</p><pre class="language-matlab">x=x+1
</pre><p>In terms of computational efficiency and speed, I'm curious how this calculation is handled. x is inclusive of itself and overwriting itself with a new value. So I assume x has to first be moved to RAM to then complete the calculation and subsequently store the new value. I have a very large script, with large matrices, many loops, and lots of similar calculations. The script takes a long time to run and I'm wondering if this is a bottleneck that slows down the script. An alternative might be as follows, but I'm not sure if I'd gain anything.</p><pre class="language-matlab">temp=x
x=temp+1
</pre><p>In this latter case, x is not inclusive of itself in the calculation, so I wonder if this is more efficient.</p><p>I'd appreciate any input.</p><p>Thanks,</p><p>M Ridzon</p>Matthewhttps://ch.mathworks.com/matlabcentral/profile/authors/1259708-matthewtag:ch.mathworks.com,2005:Question/3724492017-12-12T00:10:38Z2017-12-16T00:33:38ZMultiple computers accessing Redshift database simultaneously<p>I am accessing a Redshift PostgreSQL database from the command line using the Database Connection Toolbox. My scripts involve reading values from the database, calculating new rows from them, then appending them to the database.</p><p>If multiple machines can be running these scripts at the same time, is there a way to lock out the database for the short period of time between a single computer's read and write commands? I tried using the SQL lock command, but that did not work.</p>Tom Krajnakhttps://ch.mathworks.com/matlabcentral/profile/authors/10762691-tom-krajnaktag:ch.mathworks.com,2005:Question/3732192017-12-16T00:08:05Z2017-12-16T00:32:41ZSelect random numbers from a matrix<p>I want to select 100 random numbers from a certain column of a matrix. What should I do?</p>Pei Jiahttps://ch.mathworks.com/matlabcentral/profile/authors/11206582-pei-jiatag:ch.mathworks.com,2005:Question/3729562017-12-14T14:22:55Z2017-12-16T00:20:59ZHow to calculate the sum of errors for multiple variables?<p>Hello
I have an ODE system which solve temperature and moisture. Let's say temperature is T, and moisture is X, and "num" and "exp" stand for numerical result and experimental value. In the optimization process using "fmincon", I have a function that minimizes the error which is calculated as:</p><pre class="language-matlab">Error=sum(sqrt(T_exp-T_num).^2) + sum(sqrt(X_exp-X_num).^2)
</pre><p>However, I know that the error for temperature could be in orders of 1-5, but my moisture error is in range of 0.0001-.0005. Therefore, the effects of the temperature errors is significantly directing the solution to fit only for temperature. So I get a beautiful fitted temperature, but a skewed moisture profile. So I guess I need to know how to balance the calculated error for multiple variables that vary in totally different ranges. Or I need to use other optimization tools? Any suggestions?</p><p>Thanks</p>Hossein Aminihttps://ch.mathworks.com/matlabcentral/profile/authors/11131988-hossein-aminitag:ch.mathworks.com,2005:Question/3729912017-12-14T17:54:34Z2017-12-16T00:20:07ZTo Count the reversal of a series of numbers in a column or row.<p>I have a data with the first column as follows"
A = [1 1 1 1 2 2 2 2 3 3 3 4 4 3 3 2 2 2 3 3 3 3 4 4 4 5 5 5 5 6 6 6 6 6 7 7 7 7 8 8 8 7 7 6 6 7 7 7 8 8 8 9 9 9 9 ];
I want to count how many times the number roll back, means, form the beginning the number keep on increasing and after 4 it reversed again after 2 it start increasing. This thing happen after 7 also. So how can I make a code to count how many times it reversed? For example, in this case , the data A reversed two times. In my original data, I have almost 1000 or even more data with several reversals.</p>anepshttps://ch.mathworks.com/matlabcentral/profile/authors/4609376-anepstag:ch.mathworks.com,2005:Question/3731392017-12-15T13:32:41Z2017-12-16T00:07:55ZBar and Plot together, with Two Y axis<p>Hi,</p><p>I am trying to make a figure with Bar and Plot together, with Two Y axis. I am using 2015a, so "yyaxis" does not work. Other solutions are also not working as the Bar plot is 2*6 matrix.</p><p>I want to add another y axis, so the bar plot does not look so small. I am using the below code, please help!!</p><p>Result = [2:3; 2:3; 2:3; 2:3; 2:3; 2:3; 2:3];</p><p>EE = [100:105];</p><p>EX = [55:60];</p><p>figure('Name','Test');</p><p>bar (Result)</p><p>hold on</p><p>plot (EE, '*')</p><p>hold on</p><img src = "/matlabcentral/answers/uploaded_files/98654/untitled.jpg"><p>plot (EX, 'o')</p>Rakibul Islam Ronyhttps://ch.mathworks.com/matlabcentral/profile/authors/11701831-rakibul-islam-ronytag:ch.mathworks.com,2005:Question/3731402017-12-15T13:34:02Z2017-12-16T00:05:01ZThis error shows up when I try to convert simulink to HDL<img src = "/matlabcentral/answers/uploaded_files/98655/Capture.PNG"><p>Error: found unsupported constant inf/NaN for HDL code generation, at Function 'mod' (#33554443.2158.2193)</p>Bharadwaj Dungrothhttps://ch.mathworks.com/matlabcentral/profile/authors/9010702-bharadwaj-dungrothtag:ch.mathworks.com,2005:Question/3732002017-12-15T19:58:17Z2017-12-15T23:52:33Zwhen running lsqcurvefit to fit the complex function: F = a1*exp(-1i*x*a2) + a3*exp(-1i*x*a4), i get a2 and a4 as complex estimates, however these values should be real. how to solve this? <p>when runing lsqcurvefit to fit the complex function: F = a1*exp(-1i*x*a2) + a3*exp(-1i*x*a4), i get a2 and a4 as complex estimates, however these values should be real. how to solve this?</p>joseph chahinhttps://ch.mathworks.com/matlabcentral/profile/authors/11733486-joseph-chahintag:ch.mathworks.com,2005:Question/3732172017-12-15T23:51:39Z2017-12-15T23:51:39ZHow to convert ECI coordinates with given sidereal time to ECEF coordinates ?<p>Hey, I have an understanding problem with a project I am doing for my electrical engineering studies.
I have to calculate the position of a receiver (of satellite signals) on the earth. For that, one part of the project is to convert <b>ECI coordinates into ECEF coordinates</b>.
I have given the <b>position</b> and <b>velocity</b> of the satellite in the ECI-system as well as the <b>sidereal time</b> for each position (ca.15 min of recording in seconds, for each second position vector,velocity vector and sidereal time of the satellite are known). The <b>Julian Date</b> is also given. How do I convert these satellite positions + velocity in an ECEF-system?</p><p>I know that i can use the rotation matrix to rotate the ECI-system to the ECEF-system. I wanted to use the formula of <b>GMST(as in the picture)</b> to find out the angle between the ECI and ECEF system, so i can use that angle in my rotation matrix. The problem is, i dont know how to use the given sidereal time for each position in that equation...</p><p>I really hope someone can help me with my problem, it would be a great x-mas present!!</p><img src = "/matlabcentral/answers/uploaded_files/98730/ECI%20-ECEF.jpg">Alexander S.https://ch.mathworks.com/matlabcentral/profile/authors/10180986-alexander-stag:ch.mathworks.com,2005:Question/3730402017-12-15T00:48:32Z2017-12-15T23:26:13Zwebsave error : "Struct contents reference from a non-struct array object."<p>I try to use the websave function to save a figure from a web.
Even I tried to use the function with the example which is in the help menu, I got the same error as "Struct contents reference from a non-struct array object."</p><p>The example was :</p><pre class="language-matlab">url = 'http://heritage.stsci.edu/2007/14/images/p0714aa.jpg';
</pre><pre class="language-matlab">filename = 'jupiter_aurora.jpg';
</pre><pre class="language-matlab">outfilename = websave(filename,url)
</pre><p>--------------------------------- I got this error ----------------</p><pre class="language-matlab">Error using websave (line 95)
Struct contents reference from a non-struct array object.
</pre><p>-----------------------------------------------------------</p><p>Could you help me out, please?</p>scally12https://ch.mathworks.com/matlabcentral/profile/authors/9807273-scally12tag:ch.mathworks.com,2005:Question/3725282017-12-12T10:40:46Z2017-12-15T23:23:42ZUsing other data in Excel add in<p>This question is about using the Library compiler to create add ins for Excel. Any help or suggestions would be much appreciated.</p><p>The library compiler creates a class (default called Class1). Any functions that you add become methods of that class. My question is about the best way to use other data (not stored in Excel) in those functions.</p><p>Here's a simplified example that illustrates my issue. I have a Matlab function (Function1) that takes a single input of a column vector (n x 1). Function1 multiplies this input column vector by a (n x n) square matrix and outputs the result (which is another column vector of size n x 1). The input column vector is always multiplied by the same square matrix. The user regularly changes the input column vector and then looks at the output. At the moment, I have the square matrix saved in a workspace. When Function1 runs, it loads the workspace in order to used the square matrix.</p><p>[In reality, the data loaded from the workspace is large and varied: multi-dimensional arrays of numbers, as well as various categorical arrays, so reading it all from excel isn't my preferred option]</p><p>My issue with the system above is that every time the function runs, it loads the data, which seems to add an overhead. Is there any way for the data to be loaded once at the start and then accessed when the function runs on subsequent times?</p><p>One option that would solve my issue is if the data could be saved as class members of Class1. Is there anyway to add members/properties to Class1? The library complier dialogue only seems to let you add methods.</p><p>Thanks in advance!</p>JE101https://ch.mathworks.com/matlabcentral/profile/authors/9434020-je101tag:ch.mathworks.com,2005:Question/3728372017-12-13T22:56:13Z2017-12-15T23:22:29ZHow and where to add disturbance in simulink model?<p>I want to model the disturbance that is created by hitting the inverted pendulum on the cart. How can I do that and where can I add the disturbance in the closed loop control of the system. I am designing state space controller for SIMO system.</p>Ankitkumar Viradiyahttps://ch.mathworks.com/matlabcentral/profile/authors/8287597-ankitkumar-viradiyatag:ch.mathworks.com,2005:Question/3731982017-12-15T19:38:59Z2017-12-15T23:20:33ZHow to use logical "OR" operation for comparing string??<p>I tried with the code as given:</p><pre> strcmp('normal'||'neptune',{'normal'; 'DoS'; 'neptune'; 'R2L'})</pre><p>and the error is saying that the OR "||" operator must be convertible to logical scalar values. So, what could be the possible solution to this?? thanks in advance.</p>Shamimhttps://ch.mathworks.com/matlabcentral/profile/authors/7591009-shamimtag:ch.mathworks.com,2005:Question/3732152017-12-15T05:00:00Z2017-12-15T23:19:01ZWhy do I receive unhandled exception of type 'System.TypeInitializationException' when using .Net Assembly in C# code?<p>I am following an example given on MathWorks documentation page-</p><p><a href = "http://www.mathworks.com/help/compiler_sdk/gs/create-a-cc-application-with-matlab-code-1.html">http://www.mathworks.com/help/compiler_sdk/gs/create-a-cc-application-with-matlab-code-1.html</a></p><p>to create a .NET assembly. However, when I compile my C# code, it throws the exception:</p><p>An unhandled exception of type 'System.TypeInitializationException' occurred in MainApp.exe.</p><p>Specifically, the inner exception looks like the following:</p><p> </p><pre class="error"> {System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at MathWorks.MATLAB.NET.Arrays.MWArray.mclmcrInitialize2(Int32 primaryMode)
at MathWorks.MATLAB.NET.Arrays.MWArray..cctor()
--- End of inner exception stack trace ---
at MathWorks.MATLAB.NET.Utility.MWMCR..cctor()
--- End of inner exception stack trace ---
at makesquare.MLTestClass..cctor()}</pre><p>How can I resolve this?</p><p> </p>MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ch.mathworks.com,2005:Question/3732142017-12-15T23:16:23Z2017-12-15T23:16:23Zcan't find simpowersystems library inside simscape <p>i downloaded matlab 2016a and I have a simscape library but can't find the simpowersystems in it where can i find it or how to download it?</p>basma altayehhttps://ch.mathworks.com/matlabcentral/profile/authors/9198151-basma-altayehtag:ch.mathworks.com,2005:Question/3731622017-12-15T15:23:25Z2017-12-15T23:07:00ZMaximum number of dimensions for copulacdf('t', U, rho, nu)<p>Hi everyone,</p><p>I tried calculating the CDF of a Student t copula for a gof test, but got this error:</p><pre> Error using mvtcdf (line 195)
Number of dimensions must be less than or equal to 25.
Error in copulacdf (line 75)
p = mvtcdf(tinv(u,nu),Rho,nu);</pre><p>Is the maximum number of dimensions for this calculation really 25? The same input parameters are working for the copulapdf method.</p><p>Thanks in advance for your help.</p>Stefan Mhttps://ch.mathworks.com/matlabcentral/profile/authors/8293593-stefan-mtag:ch.mathworks.com,2005:Question/3732132017-12-15T23:05:33Z2017-12-15T23:05:33ZTime lag between 2 series: comparing xcorr max with corrcoef with different lags<p>I am trying to verify the output from xcorr wrt the lag with the highest correlation with the output from corrcoef with different lags which I adjust manually.</p><p>Xcorr gives a lag of 0 for the data below, however computing correlation coefficients with corrcoef for 0 lag vs one lag I get a higher correlation coefficient with one lag.</p><p>D=[16.654
16.056
15.424
13.91
12.974
12.765
10.846
10.42
10.009
10.827
10.666
8.946
7.775
6.612
]</p><p>E=[64.714
61.045
55.842
51.799
50.836
53.916
52.721416
50.145
51.987
50.123
40.105
33.848
28.467
27.504
]</p><p>I wonder if I am missing something and if yes any help or hint to find out what, would be great.
Thanks,</p><p>Gad</p>Gad Outmezguinehttps://ch.mathworks.com/matlabcentral/profile/authors/9588556-gad-outmezguine