http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-10-30T22:48:19Ztag:www.mathworks.com,2005:Question/1596842014-10-22T15:08:31Z2014-10-30T22:48:19ZHelp me differentiate between two codes??<p>I'm trying to understand how to use for loops and if statements in school.</p><p>I wrote a function to try to sum certain elements in a vector that are between two set parameters.</p><p>The correct function code is</p><p>function [Sum] = summing (x,a,b)</p><p>%x being a vector, a&b are the parameters</p><p>Sum = 0;</p><p>for k = 1: length(x)</p><p>if ((x(k)>=a) & (x(k)<=b))</p><p>Sum = Sum + x(k);</p><p>end</p><p>end</p><p>end</p><p>so for example is I wanted to add all the elements of vector x that are between 1 and 3 I would enter</p><p>x = [0,1,2,4,3];</p><p>summing(x,1,3)</p><p>ans = 6</p><p>I've tested this and I am content with it.</p><p>However my first attempt was to create the function</p><p>function [Sum] = Summing (x,a,b)</p><p>Sum = 0;</p><p>for k = 1:length(x)</p><p>if (a<=x(k)<=b)</p><p>Sum = Sum + x(k);</p><p>end</p><p>end</p><p>end</p><p>using the same input as before:</p><p>x = [0,1,2,4,3];</p><p>summing(x,1,3)</p><p>ans=10</p><p>I get a totally different wrong answer. Obviously my if statement is different, but I am curious as to</p><p>why the output is so different.</p><p>Can anyone enlighten me as to how my second code works? like what exactly is happening in it?</p>Radhika/matlabcentral/answers/contributors/5805910-radhikatag:www.mathworks.com,2005:Question/1607512014-10-30T22:46:53Z2014-10-30T22:46:53ZMATLAB Coder - Best practice for using lists<p>Hi,</p><p>I'm developing a sorting/detection algorithm. The best way I would think to do it in C++ would be to use lists. What would be the correct way to write it in MATLAB so that the translated C++ version uses lists? Ideally, the C++ version would take advantage of member functions like 'push_back','pop_front', etc.
Are lists even supported? Or is everything always turned into an array?</p><p>Thanks,</p>Sheida/matlabcentral/answers/contributors/5468237-sheidatag:www.mathworks.com,2005:Question/1607492014-10-30T22:19:19Z2014-10-30T22:44:26ZMeasuring intensity of sound<p>Hi All,</p><p>I have a wav file 100 seconds and I have another excel file where I marked some area of that wav file like 6 to 10, 15 to 18 seconds and so on. Now, I want to calculate the intensity parameters (like maximum , minimum, mean)of the marked area. Please give me a matlab code of how to do it.</p><p>Thanks</p>Odrisso/matlabcentral/answers/contributors/5269811-odrissotag:www.mathworks.com,2005:Question/1607502014-10-30T22:39:19Z2014-10-30T22:39:19ZCan't save simbiology model - java error<p>I am experiencing a java error that is preventing me from saving my simbiology experiment. I am running Mac OS yosemite and Matlab 2014b. I have been running 2014b on Yosemite for over a week and this is the first problem that I have encountered. There is also a java error in the command line of the main matlab window that reads:</p><p>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.mathworks.toolbox.simbio.util.tablecell.BooleanCellRenderer.getTableCellRendererComponent(BooleanCellRenderer.java:44)
at javax.swing.JTable$AccessibleJTable.getAccessibleChild(JTable.java:7039)
at com.mathworks.mwswing.MJTable$ExtAccessibleJTable.getAccessibleChild(MJTable.java:935)
at javax.swing.JTable$AccessibleJTable.getAccessibleAt(JTable.java:7426)
...along with ~100 more lines</p><p>The error code that I receive when I try to save the project is in the screenshot.</p><p>Please help! I'm worried the whole thing will crash and I'll need to rework the entire model.</p>Alex/matlabcentral/answers/contributors/4003266-alextag:www.mathworks.com,2005:Question/1601922014-10-27T04:18:15Z2014-10-30T22:22:40ZLittle help in the least square method and Antoine Equations Plz!<p>Hi I need your help with these questions :
Q1:
Use the least square methods to find the most suitable equation for fitting the
following data:</p><p>I(min): 1.02 ,0.84 ,0.69 ,0.56 ,0.38 ,0.17
CA(Ibmole/ft)): 1.5 ,2.0 ,2.5 ,3.0 ,4.0, 6.0</p><p>Test the following equation to decide which one will fit with small error:
The error = Σ(CA - CAexp )^2
1. CA = CAo exp(-kl)
2. CA= CAo I^K
3. 1/CA= CAo+ I^K
Note: CA0 and K are the equation constants (slope and intercept depends
on equation in the liner mode)</p><p>,..,.,..,...,...,..,....,....,......,......,.....,....,.....,.....,.....,....,.....,.....,</p><p>Q2:</p><p>a) Use Antoine Equations to fit the following data:
Antoine Equation : In (p*)=A- B/C+T
T(C): 30 50 100 150 200 250
p(atm): 0.042 0.122 1.00 4.70 15.36 39.22
b) caculate the pressure at temperature of 400 K ?</p><p>that's it i hope you help me and thank you</p>m ksuu/matlabcentral/answers/contributors/5824176-m-ksuutag:www.mathworks.com,2005:Question/1607362014-10-30T19:39:28Z2014-10-30T22:20:58ZSort and keep index of a n-dimension array<p>I have a 12-D array and am using each dimension as an index value in an optimization problem.</p><p>A(:,:,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10)</p><p>each index value (i) is a value from 1 to 5.</p><p>I want to sort A from greatest to least and keep track of the indices so I know which indices correspond to to what value of A.</p><p>So my ideal output would be a 2 column cell/array with one column being the value and the other other column being the index values.</p><p>Thanks, Oliver</p>Oliver/matlabcentral/answers/contributors/5842004-olivertag:www.mathworks.com,2005:Question/1607482014-10-30T22:16:24Z2014-10-30T22:16:24ZHow to calculate p-value for AR model? How to determine significance?<p>Hello everyone!!</p><p>I am using the arima model command to create an AR(2) model.
When running the program matlab tells the me value of the t-Statistic for each of the two AR parameters.</p><p>How can I tell from the output whether the parameter is significant? Is there a way to calculate the p-value for each of my two AR parameters?</p><p>Thanks alot!!</p>MC3105/matlabcentral/answers/contributors/5543488-mc3105tag:www.mathworks.com,2005:Question/1607472014-10-30T22:12:39Z2014-10-30T22:12:39ZRead a text file with a common name <p>Hi,
I have a program X that generate each time a text file (including some numbers in the file) with a specific name that reflects the current iteration number i.e. "App.in.1", "App.in.2",... . The program X delete the old file (e.g. "App.in.1") after each iteration and creates a new file (e.g. "App.in.2").</p><p>I want to have a matlab code that be able to automatically read the current file that include "APP.in." (for example "APP.in.50"), get the iteration number say 50, do some operations, and write back a new file ""APP.out.50". Program X then takes over this text file and deletes it afterwards.</p><p>How to write such small matlab code that can read the current file name at time n "App.in.n", and write back a file with name "App.out.n"</p><p>Thank you.</p>H-H/matlabcentral/answers/contributors/4648325-h-htag:www.mathworks.com,2005:Question/1604812014-10-28T21:55:17Z2014-10-30T22:07:32ZFind s, such that det(A+s*D) = d.<p>Given a non-sigular matrix A, an arbitrary matrix D, and a real or complex number d, I want to see any short-cut to find the numerical number s, such that M = A+s*D, and det(M) = d.
Specially, the matrix M is singular if d = 0.</p>Feng Cheng Chang/matlabcentral/answers/contributors/1277043-feng-cheng-changtag:www.mathworks.com,2005:Question/1607452014-10-30T21:44:33Z2014-10-30T22:07:13ZGPU computation error: please help<p>HI all, I want to use GPU in my research.
I downloaded simple example from mathworks (code is attached).
Basically, code is:</p><p>A = magic(5000);</p><p>AonGPU = gpuArray(A);</p><p>f = ones(1,20)/20;</p><p>BonGPU = filter(f, 1, AonGPU);</p><p>On the last line there is an error:</p><p>Error using parallel.gpu.GPUArray/filter
An unexpected error occurred trying to launch a kernel. The CUDA error was: CUDA_ERROR_INVALID_VALUE.</p><p>Error in ex_gpu (line 14)
BonGPU = filter(f, 1, AonGPU);</p><p>Can someone help please?
My GPU is NVIDIA GeForce GTX 650 Ti (According to device manager), Windows 7 64 bit.
I've installed the latest driver, as listed here <a href = "http://www.mathworks.com/products/availability/index.html#DM">http://www.mathworks.com/products/availability/index.html#DM</a></p><p>Thanks!</p>Mikhail/matlabcentral/answers/contributors/5492695-mikhailtag:www.mathworks.com,2005:Question/1607242014-10-30T17:54:59Z2014-10-30T22:01:53ZReconstruct Gaussian fitted Beads<p>I have gaussian fitted a bead in an image and I have its x & y coordinate, standard deviation (std) of the gauss fit as well as amplitude (amp). Is there a way to reconstruct the bead from the x,y,std & amp values?</p>John/matlabcentral/answers/contributors/2986627-johntag:www.mathworks.com,2005:Question/1607422014-10-30T20:47:42Z2014-10-30T21:56:14ZHow to use interpolation to transform data of one resolution onto the same grid as data of another resolution?<p>I have bathymetry data at a 2-minute resolution, for an 8 degree by 10 degree area over the bay of Biscay, and chlorophyll satellite data, for the same area, at a 9km resolution.</p><p>I need to use an appropriate interpolation technique to transform the chlorophyll dataset for the area onto the same grid as the bathymetry dataset.</p><p>Any pointers? I don't even know where to start I tried to read the grid-based interpolation section on matlab but I just couldn't get my head round it.</p><p>Oh and there are 60 minutes in a degree if longitude/latitude and 111km in a degree.</p><p>Thank you!!</p>Emma Whettall/matlabcentral/answers/contributors/5082066-emma-whettalltag:www.mathworks.com,2005:Question/1607392014-10-30T20:01:38Z2014-10-30T21:53:02ZMATLAB is not recognizing .h5 files; do I need a different version?<p>I've downloaded VIIRS satellite data from NOAA/CLASS in .h5 format and tried to import it into MATLAB but .h5 is not recognized. Is there another version I need (R2013a) or am I doing something wrong?</p>David McDonald/matlabcentral/answers/contributors/5681983-david-mcdonaldtag:www.mathworks.com,2005:Question/1607292014-10-30T18:15:34Z2014-10-30T21:49:59ZFigure out the waveguide width at cutoff (d) for each of TE0,TE1,TE2 and TE3 modes. Assume n1=1.48, n2=1.46 and wavelength is .82um. Sketch the transverse mode patterns (Ey(x)) at cutoff for TE0 and TE1.<pre class="language-matlab">m=(2d/lambda)*(sqrt(n1^2-n2^2))
</pre><p>I am looking for the relation as given in the attachment.</p><p><a href = "https://www.wlu.ca/documents/53119/notesch3.pdf">https://www.wlu.ca/documents/53119/notesch3.pdf</a></p>garry/matlabcentral/answers/contributors/5841557-garrytag:www.mathworks.com,2005:Question/1607462014-10-30T21:47:57Z2014-10-30T21:50:03Zhow do i debug my program<p>i have here a picture of the problam and also i attached here the code which is going wrong. what i am trying to do is to update the info in the vector integ(i) by summerizing each cell with the integral's calculation. for this iam writing integ(i)= int(...) + integ(i)
however for some reson, as you can see in the picture below (click on it) i highlight in red that the values are 0 and i don't understand why it is not being updated with new values. please help me to correct my code.</p><pre class="language-matlab">l=1;
h=l/10;
n=round(l/h);
syms t j
K(t)=exp(-t);
F(t)=t;
integrand(t,j) = K(t-j)*F(j);
U(t)=1 - int(integrand(t,j),j,0,t);
Uexact=zeros(1,n+3);
Utest=zeros(1,n+3);
integ=zeros(1,n+3);
Udiff=zeros(1,n+3);
LOGtest=zeros(1,n+3);
ERRORord=zeros(1,n+3);
for i=2:n+1
for m=1:i
integ(i)=int(K((i-1)*h-j)*(1/h)*((F(m*h)-F((m-1)*h))*j+h*(i*F((m-1)*h-(m-1)*F(m*h)))),j,(m-1)*h,(m*h))+integ(i);
end
</pre><img src = "/matlabcentral/answers/uploaded_files/20250/%D7%91%D7%A2%D7%99%D7%99%D7%94%201.jpg">JACK/matlabcentral/answers/contributors/5810442-jacktag:www.mathworks.com,2005:Question/1605162014-10-29T06:25:43Z2014-10-30T21:47:42ZFastest way to search for a short vector in a huge array?<p><b>Background</b></p><p>I have a 16GB text file, which is some kind of dump of a datacube. Each "observation" represents a measured value, e.g. temperature. There are four dimensions (keys). The size itself is a challenge.</p><p>The profiler tells me that finding the occurrences of combinations of key-values takes a lot of time. I tested with   <tt>ismember(...,'rows')</tt>,   <tt>strfind</tt>  (us' trick) and with   <tt>bsxfun</tt>.   The latter is the fastest in all my tests.</p><pre>  </pre><p><b>Questions</b></p><p>The results of   <tt>bsxfun_performace</tt>   show the   <tt>bsxfun</tt>   is twice as fast searching for rows than searching for columns. I stumbled upon this and cannot understand.</p><p>Ouestion</p><ol><li>is it expected that searching for rows should be faster (in this case)?</li><li>is there an even faster way to search for a short vector in a huge array?</li></ol><p>My test</p><pre> >> [ ok, et ] = bsxfun_performace( 1e7 )
ok =
1
et =
0.0631 0.1241 0.1024</pre><p>where</p><pre> function [ ok, et ] = bsxfun_performace( N )</pre><pre> keyr = randi( [0,127], [N,4], 'uint8' );
krow = randi( [0,127], [1,4], 'uint8' ); </pre><pre> tid = tic;
iskr = all( bsxfun( @eq, keyr, krow ), 2 );
et(1,1) = toc(tid);
%
keyc = transpose( keyr );
kcol = transpose( krow );
tid = tic;
iskc = all( bsxfun( @eq, keyc, kcol ), 1 );
et(1,2) = toc(tid); </pre><pre> ok = all( iskr == transpose(iskc), 1 );</pre><pre> keyr = randi( [0,127], [N,4] );
krow = randi( [0,127], [1,4] );
tid = tic;
iskr = all( bsxfun( @eq, keyr, krow ), 2 );
et(1,3) = toc(tid);
end</pre>per isakson/matlabcentral/answers/contributors/1670-per-isaksontag:www.mathworks.com,2005:Question/1607442014-10-30T21:43:57Z2014-10-30T22:02:22Zlarge differences between continuous and discrete tf<p>Hello,</p><p>While working on an assignment, I noticed some differences between continuous and discrete tf and I cannot figure out where's the problem. Here's a script where I have isolated it:</p><pre class="language-matlab">% RST
Te = 0.05;
num = [0,0,0,0.426762811098847,0.479098720565413];
den = [1,-1.38166420132806,1.58283601345288,-1.30344677697330,0.921017027200194];
</pre><pre class="language-matlab">Gd = tf(num,den,Te);
</pre><pre class="language-matlab">Rc = [ 0.2960 -0.1046 -1.0714 1.1482];
Sc = [ 1.0000 0.4172 -0.8199 -0.5973];
Tc = [ 0.2682];
</pre><pre class="language-matlab">% sensitivity TF
</pre><pre class="language-matlab">K1d=tf(Tc,Sc,Te);
K1c=tf(Tc,Sc);
K2d=tf(Rc,Sc,Te);
K2c=tf(Rc,Sc);
</pre><pre class="language-matlab">Gc = d2c(Gd,'tustin');
</pre><pre class="language-matlab">Lc = series (K2c,Gc);
Ld = series (K2d,Gd);
</pre><pre class="language-matlab">Sc = inv(1+Lc);
Sd = inv(1+Ld);
</pre><pre class="language-matlab">Tc = feedback(Lc,1);
Td = feedback(Ld,1);
</pre><pre class="language-matlab">K2Sd = K2d*Sd;
K2Sc = K2c*Sc;
</pre><pre class="language-matlab">GSc = Gc * Sc;
GSd = Gd * Sd;
</pre><pre class="language-matlab">% plots
</pre><pre class="language-matlab">subplot(2,2,1);
sigma(Sc,Sd); title('S');
subplot(2,2,2);
bodemag(Tc,Td);title('T');
subplot(2,2,3);
bodemag(K2Sc,K2Sd);title('KS');
subplot(2,2,4);
bodemag(GSc,GSd);title('GS');
</pre><p>and the output:</p><img src = "/matlabcentral/answers/uploaded_files/20249/comp.png"><p>Since I'm working with sensitivity functions, I guess that the discrete version (green plots) is closer to reality, and the problem might start at the d2c call.</p><p>Do you have any idea where do these differences come from?</p><p>Thank you.</p>George Sterpu/matlabcentral/answers/contributors/3613906-george-sterputag:www.mathworks.com,2005:Question/1607272014-10-30T18:05:38Z2014-10-30T21:33:53ZAny recommendation how to vectorize this double for loop?<p>I am a beginner in Matlab, and I would like to speed up the following:</p><pre class="language-matlab">X = 100;
MA = NaN(X,3);
for looper = 1:X
compareDist = inf;
array = MM(looper,:);
for looper2 = 1:size(array,1)
currPoint = cell2mat(C(looper,looper2));
currDist = distancePoints3d(pP, currPoint);
if(~isnan(currPoint(1))&&currDist<compareDist)
compareDist = currDist;
MA(looper,:) = currPoint;
end
end
end
</pre><p>Any help is appreciated. Thanks.</p>UCL student/matlabcentral/answers/contributors/4746756-ucl-studenttag:www.mathworks.com,2005:Question/1582442014-10-11T10:03:15Z2014-10-30T21:29:41Zconverting a minute chart<p>Hi guys, i have a table with 6 columns and 4 million rows. Column1 shows the date and column 2 the time. Column 3 the opening price, column4 the max price, column5 the min price and column6 the closing price. The whole table presents a one minute chart. I want to convert this to a two minute chart in the following manner: two rows have to be combined(row1 and row2). Column
1,2,3 should have the values of row1. Column4 should contain the max value of row1 and row2. Column 5 should have the min value of row1 and row2. Column6 should have theclosing value of row2.</p>AA/matlabcentral/answers/contributors/5703029-aatag:www.mathworks.com,2005:Question/1607432014-10-30T21:00:38Z2014-10-30T21:24:38ZStructuring a cell based on irregularly sized arrays.<p>I'd like to create a cell array that has three items, the first two will be single values, but the third column will contain factors of numbers. This column is therefore variable in size. The closest way I've managed to get the expected behavior (each single item in the last column visible) is by using the following type of code:</p><pre> >> {cell(factor(625));cell(factor(125));cell(factor(25));cell(factor(17))}</pre><pre> ans = </pre><pre> { 4-D cell}
{ 5x5x5 cell}
{ 5x5 cell}
{17x17 cell}</pre><p>As you can see, it works for composite numbers with 2 or 3 factors, and semi-works (kinda odd behavior) for primes. However, it goes into "dimensional mode" when there are n>=4 factors.</p><p>So I'm wondering if anyone has got a good enough grasp of the subjects to provide a working example? Either that or refute the possibility of what I'm trying to do. :)</p><p>Here is the exact code line I'm using for the cell creation btw (i and b are integers):</p><pre> list(idx,:) = {i,b,cell(factor(i))};</pre><p>Grateful for all suggestions!</p>Matt Eri/matlabcentral/answers/contributors/2021814-matt-eritag:www.mathworks.com,2005:Question/563582012-12-12T04:28:49Z2014-10-30T21:11:58ZFinding Joint Angle from Motion Capture<p>Hi!</p><p>I'm working right now with data from a motion capture device, essentially picking up data for three markers placed on the head neck and shoulder in an x y z plane.</p><p>My difficulty trying to develop a code to calculate the joint angles between these three markers. I am able to animate the three coordinates to play as an animation, but I'm more interested in the calculation of the angles between these points changing over time.</p><p>Any ideas on how to go about this?</p><p>Thanks</p>Mary/matlabcentral/answers/contributors/2000413-marytag:www.mathworks.com,2005:Question/1600592014-10-25T15:01:39Z2014-10-30T20:59:12ZFinding the frequency value of a signal <p>How can I find the frequency of this signal?</p><p>Thanks,</p><img src = "/matlabcentral/answers/uploaded_files/19973/ils.png">Ramo/matlabcentral/answers/contributors/4735443-ramotag:www.mathworks.com,2005:Question/1605962014-10-29T18:02:06Z2014-10-30T20:54:19ZRead all the columns in a .csv file<p>Hi,</p><p>I have a .csv file with the following columns, I need to read all the columns. What function I need to use. I tried csvread but it did not work.</p><pre class="language-matlab">KH 110427 PH M 1951-01-01T07:00:00+07:00 0 mm O
KH 110427 PH M 1951-01-02T07:00:00+07:00 0 mm O
KH 110427 PH M 1951-01-03T07:00:00+07:00 0 mm O
.
.
.
</pre><p>Any ideas?</p><p>Thanks.</p>Damith/matlabcentral/answers/contributors/5131512-damithtag:www.mathworks.com,2005:Question/1607412014-10-30T20:39:23Z2014-10-30T20:44:44ZAnother way to create a string of lowercase letters?<p>I'm trying to create a function that will create a string of as many lowercase characters from a-z as specified by the input.</p><p>Here's my code, which does work:</p><pre class="language-matlab">function [y] = func1(x)
s = 'abcdefghijklmnopqrstuvwxyz';
n = length(s);
slength = x;
y = s(round(rand(1,slength)*n));
end
</pre><p>How can I write this function instead using the randi and char built-in functions?</p>n/matlabcentral/answers/contributors/5811072-ntag:www.mathworks.com,2005:Question/1607342014-10-30T18:53:48Z2014-10-30T20:40:37Zdection of a word inside a condition (if)<p>I have programmed a code and I would like Matlab to recognise the word of materials (steel and aluminium). Any idea?</p><p>Following I put the code:</p><pre class="language-matlab">function y=kfgraf(r,Sut,material)
</pre><pre> a=xlsread('kf.xls'); %Extret del webplotdigitizer
x1=a(1:67,1);
y1=a(1:67,2);
x2=a(1:65,3);
y2=a(1:65,4);
x3=a(1:64,5);
y3=a(1:64,6);
x4=a(1:63,7);
y4=a(1:63,8);
x5=a(1:59,9);
y5=a(1:59,10);</pre><pre> if material==steel && Sut<=0.4</pre><pre> i1=interp1(x1,y1,r,'spline');
y=i1
end</pre><pre> if material==steel && Sut>0.4 && Sut<=0.7</pre><pre> i1=interp1(x1,y1,r,'spline');
i2=interp1(x2,y2,r,'spline');</pre><pre> prop=((Sut-0.4)/(0.7-0.4))
y=i1+prop.*(i2-i1);
end</pre><pre> if material==steel && Sut>0.7 && Sut<=1</pre><pre> i1=interp1(x2,y2,r,'spline');
i2=interp1(x3,y3,r,'spline');</pre><pre> prop=((Sut-0.7)/(1-0.7))
y=i1+prop.*(i2-i1);
end</pre><pre> if material==steel && Sut>1 && Sut<=1.4</pre><pre> i1=interp1(x3,y3,r,'spline');
i2=interp1(x4,y4,r,'spline');</pre><pre> prop=((Sut-1)/(1.4-1))
y=i1+prop.*(i2-i1);
end</pre><pre> if material==steel && Sut>=1.4</pre><pre> i1=interp1(x4,y4,r,'spline');
y=i1
end</pre><pre> if material==aluminium</pre><pre> i1=interp1(x5,y5,r,'spline');
y=i1
end
end</pre>Josep/matlabcentral/answers/contributors/5500833-joseptag:www.mathworks.com,2005:Question/1607172014-10-30T16:20:34Z2014-10-30T20:37:40Zwhat is image level<p>hi i have some questions about image 's levels i should insert a watermark in 0 ,3 and 7 level of an image and calculate robustness against jpg, Gaussian noise attack but i do not know how to access these levels? is bitset function suitable for this?
thanks</p>nadia/matlabcentral/answers/contributors/5841148-nadiatag:www.mathworks.com,2005:Question/1607152014-10-30T16:15:02Z2014-10-30T20:35:08ZHow to change particular pixel color of a binary image to other color?<p>Sir,</p><p>I have a binary image and i want to change the color of the black pixel to green. How do i do that ? Please help.
Thanks in advance.</p><p>This is the binary image:</p><img src = "/matlabcentral/answers/uploaded_files/20230/binary.jpg">Asif Hasan/matlabcentral/answers/contributors/5287485-asif-hasantag:www.mathworks.com,2005:Question/1582682014-10-11T15:35:59Z2014-10-30T20:23:49Zsample rate of a DUC object<p>Hi,</p><p>I’m using the DUC system object to make frequency upconversions: <a href = "http://www.mathworks.com/help/dsp/ref/dsp.digitalupconverter-class.html">http://www.mathworks.com/help/dsp/ref/dsp.digitalupconverter-class.html</a> .</p><p>Question: Does the output sample rate equal to SampleRate * InterpolationFactor?</p><p>Owen</p>Owen/matlabcentral/answers/contributors/3588526-owentag:www.mathworks.com,2005:Question/1607142014-10-30T16:06:35Z2014-10-30T20:23:48Zcurve fit with ode bad fit ??<p>Hi, I'm a grad student with minimal matlab experience trying to complete this curve fit. My data has a logarithmic shape and is (hopefully) described by one ODE out of a system of 11 ODEs with 15 parameters. The only info I know is initial conditions of ODEs and some of the ratios of the parameters (so individual parameter values can vary greatly).</p><p>I have gotten my output to look logarithmic by manual manipulation of parameters (fig 1; data = blue, model = green circles), but when I try to get it to curve fit the output is always linear, usually intersecting in 2 places but sometimes not at all (fig 2: data = blue, model = green). (dont even know how its getting 10^22 with the bounds I specified)</p><img src = "/matlabcentral/answers/uploaded_files/20226/manualfit.jpg"><img src = "/matlabcentral/answers/uploaded_files/20227/untitled.jpg"><p>I have heard of using global search as a possible solution, but I have the curve fitting toolbox and it doesnt like my system of ODE (probably because I dont know what im doing), so if someone can tell me that the global search toolbox will definitely work with a system of ODE then i'll give it a shot (because its going to take me forever lol).</p><p>curve fit code:</p><pre class="language-matlab">y = xlsread('dataforfitting.xlsx','B2:B1201');
t = xlsread('dataforfitting.xlsx','A2:A1201');
%init values for params
c0=[7000000000;.0000001;50000000;.000001;30000;.001;260000;.0001;.5;.05;.0000001;2;.1;450000000000000000000;.5];
%bounds for params
lb = [6000000000;.0000001;40000000;.000001;20000;.0001;200000;.00001;.4;.01;.00000001;1;.01;300000000000000000000;.1];
ub = [8000000000;.000001;500000000;.00001;300000;.01;300000;.001;.6;.1;.000001;5;1;550000000000000000000;1];
%curve fit
options = optimoptions(@lsqcurvefit,'ScaleProblem','Jacobian','MaxIter',20000,'MaxFunEvals',20000);
cfit = lsqcurvefit(@fitodes,c0,t,y,lb,ub,options);
% See results
plot(t,y,'o',t,fitodes(cfit,t))
</pre><p>ode code:</p><pre class="language-matlab">function y = fitodes(c,x)
% Define ODE system with parameter c
f = @(t,y,c) [c(1).*x(4)-c(2).*x(1).*x(3)+c(3).*x(6)-c(4).*x(1).*x(5);c(5).*x(5)-c(6).*x(2).*x(3)+c(7).*x(6)-c(8).*x(4).*x(2);c(9).*c(10).*x(10).^c(12).*x(10).^c(12)-c(9).*c(11).*x(11)+c(5).*x(5)-c(6).*x(2).*x(3)+c(1).*x(4)-c(2).*x(1).*x(3);-c(1).*x(4)+c(2).*x(1).*x(3)+c(7).*x(6)-c(8).*x(4);c(6).*x(2).*x(3)-c(5).*x(5)+c(3).*x(6)-c(4).*x(1).*x(5);-c(7).*x(6)+c(8).*x(4)-c(3).*x(6)+c(4).*x(5).*x(1)-c(13).*x(6);c(14)*c(15).*x(6)-x(7);c(13).*x(6)*c(15);c(13).*x(6)*(1-c(15));-c(10).*x(10).^c(12).*x(10).^c(12)+c(11).*x(11);c(10).*x(10).^c(12).*x(10).^c(12)-c(11).*x(11);];
%error
options= odeset('RelTol',1e-6);
%init conditions
init =[20000;75;0;0;0;0;0;0;0;.45;0;];
%solve
[~,z] = ode45(@(t,y) f(t,y,c),x,init,options);
% Extract desired solution component
y = z(:,7);
</pre>Renee/matlabcentral/answers/contributors/5776429-reneetag:www.mathworks.com,2005:Question/1603412014-10-28T01:26:48Z2014-10-30T20:23:31ZWhy polynomial roots are not continuous?<p>I have a 4th order polynomial with real constant coefficients for which I use Matlabs "roots" function to determine the expressions for the 4 roots. When I plot each of the expressions for the complex roots as a function of a real continuous dependent variable X, I see a "jump" in all four roots, as if the expressions are interchanged. The "jump" is a result of something on Matlab's end. I spoke with a mathematics professor, and it was acknowledged that my solution was correct with exception to the "jump". All four roots should be continuous. The roots do not intersect and thus it is not an issue of branch points. I can not figure out why the complex root expressions generated by Matlab are not continuous when they should be. Any thoughts?</p><img src = "/matlabcentral/answers/uploaded_files/20075/image.png"><p>I should note that I came across a similar problem here: <a href = "http://www.mathworks.com/matlabcentral/answers/133961-fixing-the-root-of-polynomial">http://www.mathworks.com/matlabcentral/answers/133961-fixing-the-root-of-polynomial</a>
but the accepted solution is a brute force work around to force continuity. I have to run my problem through an optimization algorithm, so I can't rely on brute force methods to work over all independent cases. I need matlab to return a continuous expression for each root.</p><p>Here is my code:</p><pre class="language-matlab">syms X
</pre><pre class="language-matlab">% Coefficients
B(1) = 2;
B(2) = -19/12;
B(3) = 2/3;
B(4) = -1/12;
</pre><pre class="language-matlab">Cval = [B(4); B(3); B(2); (B(1) + 1i/X); -1i/X];
ROOTS = roots(Cval); % <- THIS IS EVALUATED SYMBOLICALLY.
% EACH ROOT IS A FUNCTION OF "X"
</pre><pre class="language-matlab">fcolor = {'r','b','m','g'};
figure
for n = 1:length(ROOTS)
subplot(2,1,1)
F1 = ezplot(real(ROOTS(n)),[0 pi]);
set(F1,'Color',fcolor{n})
ylabel 'Re(roots)'
title ''
axis tight
hold on
</pre><pre> subplot(2,1,2)
F2 = ezplot(imag(ROOTS(n)),[0 pi]);
set(F2,'Color',fcolor{n})
ylabel 'Im(roots)'
title ''
axis tight
hold on
end</pre><p>I should note that my original plot is for a different set of coefficients. The plot generated from the code above will differ, but still show the problem I'm facing...there should be no "jump".</p><p>My goal is to analyse one of the root expressions in an optimization process, but I can't do so if Matlab includes the "jump" in what should be a continuous expression.</p>Troy/matlabcentral/answers/contributors/1732034-troytag:www.mathworks.com,2005:Question/1581952014-10-10T18:23:57Z2014-10-30T20:09:15ZPlot adaptive filter coefficients<p>Hello,</p><p>I would like to plot the time series of the coefficients from an adaptive filter object, in order to watch the convergence of my filter coefficients. How can I do this?</p><p>For example, using the example provided at the bottom of <a href = "http://www.mathworks.com/help/dsp/ref/adaptfilt.html">http://www.mathworks.com/help/dsp/ref/adaptfilt.html</a></p><p>How do I plot the time series of filter coefficients for each step, rather than just the final values?</p><p>Thanks</p>Cory Larsen/matlabcentral/answers/contributors/2823780-cory-larsentag:www.mathworks.com,2005:Question/1605052014-10-29T02:12:02Z2014-10-30T20:01:57ZHow do I plot a 2D graph of a lay out hospital ward ?<p>I'm doing a project on path planning algorithm for a hospital environment and I am not certain how to create a 2-D lay out of a hospital ward. Must I use GUI to design the layout? Or can I just use the mat lab function, plot(X,Y), to create the lay out? Is it possible to give examples or codes for me to try out. Thank you.</p>Muhammad Aiman/matlabcentral/answers/contributors/5504950-muhammad-aimantag:www.mathworks.com,2005:Question/1597302014-10-22T20:39:11Z2014-10-30T19:53:53Zkeeping the distance between objects<p>Hello world,</p><p>Think of two linear trajectories. Hooks will be moving along those trajectories with "rope" tied between them - hook1 from traj1 with hook1 from traj2 with hook2 from traj1 with hook2 from traj2 and so forth. The two trajectories are in one plane with the center line, symmetrically at an angle around the center line and the hooks need to decelerate to 0 along the trajectory. To simplify, there'll be no queue forming at one end.</p><p>I know the timing of hooks because I know the speed of new rope coming in and the length of the rope between hooks. I have found equations for the trajectories, created 1x* matrizes for time and position according to the resolution I will be able to control the hooks at and decided the deceleration along the centerline should be linear for simplicity. What I'm now trying to do is output a lookup table of position (and speed) along either trajectory and the time for that position. As there's nothing dynamic this table will be looped through for each new hook.</p><p>I have thought of few ways to go about this, each looks equally beyond my ability right now so I'm hoping for your support.</p><p>1. Try to program "free particles" that will be bound by the boundary conditions a) the trajectory b) the distance to the one coming after. It seems to me this would incur great performance tribute.</p><p>2. Try to program a circle with the diameter of the distance between two hooks and let that decelerate linearly along the centerline. I don't know how to check the intersections with the trajectories and how to properly adapt the speed of either of the hooks along their trajectories.</p><p>3. Perhaps someone could do this with higher-than-I-could-come-up-with differential maths?</p><p>4. Perhaps I'm not seeing some easy relationship between the centerline and trajectoral deceleration that would save me all of the above work?</p><p>I do hope somebody can give me very easy to understand advice / instructions on which idea would be best and how to actually do it.</p><p>Thank you very much!
Philipp</p>Philipp/matlabcentral/answers/contributors/4302723-philipptag:www.mathworks.com,2005:Question/1598542014-10-23T17:07:38Z2014-10-30T19:51:16Zcurve fit toolbox help system ODE and excel?<p>Hi, I am trying to curve fit using the toolbox to a function which is a system of ODE. my data corresponds to one equation of the function. how can i specify this? Also, the tutorial seems to say you should put your data into the command line, but mine is in excel, is there some easier way? Thanks!</p>Renee/matlabcentral/answers/contributors/5776429-reneetag:www.mathworks.com,2005:Question/1607382014-10-30T19:48:36Z2014-10-30T19:48:36Z.tlc files missing in c2000 embedded package<p>in TI c2000 package .tlc files are missing</p>Girish karamadi/matlabcentral/answers/contributors/2455270-girish-karamaditag:www.mathworks.com,2005:Question/1605382014-10-29T09:34:38Z2014-10-30T19:46:06ZHow Do you have a file Hex for arduino?<p>Hello,</p><p>I want to have a file .hex for test this in proteus, but n i don't know how do it.
i have support target arduino in simulink, but i don't have yet the hardware arduino.</p><p>Do you have a solution for this?</p><p>Thanks you</p>Mus/matlabcentral/answers/contributors/4407206-mustag:www.mathworks.com,2005:Question/1590032014-06-16T04:00:00Z2014-10-30T19:43:31ZWhy am I unable to install or start MATLAB on OS X 10.10 Yosemite?<p>After installing OS X 10.10 I am no longer able to launch or install MATLAB.</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/1604672014-10-28T19:21:19Z2014-10-30T19:41:48ZCannot export to excel<p>Simbiology 5.0 (R2014a) cannot export data to excel 2013.</p><p>Excel is not an option in the export data menu!</p><p>I already tried reinstalling Matlab and it didn't work!</p><p>Any suggestion</p>Peter Madelung/matlabcentral/answers/contributors/3989797-peter-madelungtag:www.mathworks.com,2005:Question/1607372014-10-30T19:39:30Z2014-10-30T19:39:30ZUnable to Enumerated data with Chart in simulink<p>I have defined my class as shown below.</p><pre class="language-matlab">classdef(Enumeration) TrafficColors < Simulink.IntEnumType
enumeration
RED(0)
GREEN(10)
end
end
</pre><p>I am trying to use this in my chart in simulink, but I am not able to compile the code.</p><p>I am trying to assign a value to the variable defined in my chart with class at TrafficColor.</p><p>I have attached the copy of my code here.</p><p>Please advise.</p>Claude Porlier/matlabcentral/answers/contributors/3907159-claude-porliertag:www.mathworks.com,2005:Question/1607352014-10-30T19:37:27Z2014-10-30T19:37:27Zi want to find angle between two 3d dots in kinect skeleton<p>if i want to find angle of btween kneejoint and hipjoint,
how can i do? just i knew only x,y,z values of joints...
somebody help me plz..</p>TAEYUN/matlabcentral/answers/contributors/5841600-taeyuntag:www.mathworks.com,2005:Question/1606112014-10-29T19:57:32Z2014-10-30T19:36:12ZHow to have Tree able to do Multiple Splits at each Node rather than just 2 using fitctree?<p>All the trees I've produced have two splits at each node, but sometimes this is not optimal.
How can I set fitctree to allow for multiple splits of a variable?</p><p>I suppose tree could split x2 and then split again using the same predictor...perhaps my interest in multiple splits is irrelevant to quality of results?</p>Justin/matlabcentral/answers/contributors/4408666-justintag:www.mathworks.com,2005:Question/162432011-09-20T10:34:45Z2014-10-30T19:27:05ZAngle between two vectors in 3d<p>Hello,</p><pre> I have two vectors in 3d and i want to find the angle between those two vectors.</pre><p>Thanks in advance</p>developer/matlabcentral/answers/contributors/2798625-developertag:www.mathworks.com,2005:Question/1604592014-10-28T18:15:25Z2014-10-30T19:24:48ZSymbolic array pre-allocation <p>Symbolic array pre-allocation only allocates pointers as I understood it from reading the forum. This is causing a major slowdown in code we are looking at</p><pre class="language-matlab">a=sym(zeros(50000,1));
</pre><p>Filling the area with relatively simple expression e.g. '3+sqrt(5)/sqrt(7)' a serious slowdown is noted around the 9000th index.</p><p>Would it be possible to allocate memory by defining the sym array (in the definition) with large expressions '3+sqrt(1)+sqrt(2)+sqrt(3)+sqrt(4)+sqrt(5)+sqrt(6)+sqrt(7)' for all elements 1:50000, so that effectively a memory allocation is forced at the definition step. Is this possible in the definition of sym? I tried repmat, but didn't get it too work.</p>lvn/matlabcentral/answers/contributors/4235257-lvntag:www.mathworks.com,2005:Question/1599582014-10-24T16:44:21Z2014-10-30T19:19:48ZWriting a script for multiple arrays with a set criteria for each array and identifying certain value locations<p>I am working with arrays of data, where each value is a latitude and longitude grid point - columns are longitude and rows are latitude.</p><p>There are three arrays of equal size, representing the same latitude-longitude grid points over the Earth. Each array however contains a different type of data: the first, temperature; the second, wind; the third, height of the atmosphere.</p><p>I want to develop a script which identifies certain grid points according to some criteria:
The process:</p><ol><li>scanning the first array for if certain values are 20 units less than the surrounding grid points</li><li>For these locations of where minimum values are, scanning the second array to check whether the value two places above it is negative.</li><li>For these locations where the both the minimum values are (for the first array) and two places above is negative (for the second array), scanning the third array for where the value to the right of the location must be greater.</li></ol><p>I presume this will require if statements and for loops.</p><p>For Example:</p><p>1st array</p><pre class="language-matlab">30 30 30 30 30 30 30 30
30 30 30 30 30 10 30 30
30 20 30 30 30 30 30 30
30 30 30 10 30 30 30 30
30 10 30 30 30 30 30 30
30 30 30 30 30 30 30 30
</pre><p>2nd array</p><pre class="language-matlab">22 22 22 22 22 22 22 22
22 22 22 -5 22 22 22 22
22 -5 22 22 22 22 22 22
22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22
</pre><p>3rd array</p><pre class="language-matlab">100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
100 100 100 100 200 100 100 100
100 100 200 100 100 100 100 100
100 100 100 100 100 100 100 100
</pre><p>The script would scan array 1, find the values, scan array 2 at those values lcoations, if it matches critera, it scans array 3 at these lcoations, if it matches the criteria, creates a lsit of the row and column where the lcoations match all 3 criteria.
for the above example it would be row and column ([r c]):</p><pre class="language-matlab">4 4
5 2
</pre><p>because in row 5, column 2:</p><p>1)10 is less than surrounding eight grid points, 2) the -5 two above it is negative and 3) the 200 is greater than 100.</p><p>Thanks for any help</p>Oliver/matlabcentral/answers/contributors/5671757-olivertag:www.mathworks.com,2005:Question/1607302014-10-30T18:17:26Z2014-10-30T19:17:45ZDisplaying images using different color spaces<p>Hello,</p><p>I have images that are defined by u'v'L or L*u*v*. Is there a way to display these images using either of these color spaces, or do I have to convert to RGB?</p><p>(I tried using makecform and applycform to go from u'v'L --> XYX --> RGB, but I'm not sure what I'm looking at is correct.)</p>Megan/matlabcentral/answers/contributors/5756957-megantag:www.mathworks.com,2005:Question/1605852014-10-29T16:04:51Z2014-10-30T19:04:56ZDocumentation for mwArray for those without a license<p>My company produces software in Matlab and compiles it with the Matlab compiler, producing a *.dll that we distribute to our customers. It seems that the documentation for the various Matlab data types (e.g. mwArray or mxArray) is only accessible to those with a Matlab license. Are there other documentation pages that Mathworks has for those that do not have a license?</p>Tyler Cumby/matlabcentral/answers/contributors/4184289-tyler-cumbytag:www.mathworks.com,2005:Question/1605272014-10-29T08:26:31Z2014-10-30T18:57:30Zi cannot make mex setup command to work on my matla2012a?<p>hello all, i am trying to use mex setup command on matlab 2012a but it does not work on my laptop, and i get the error "Previously accessible file "C:\Program Files\MATLAB\R2012a\toolbox\matlab\iofun\tempname.m" is now inaccessible." any ideas??</p>bena/matlabcentral/answers/contributors/5002427-benatag:www.mathworks.com,2005:Question/1607332014-10-30T04:00:00Z2014-10-30T18:49:04ZHow to I merge a column from one table into the column of another table that has missing entries?<p>I have two tables with different column names and different number of rows. Column 3 of table A for example is missing some entries that are present in column 2 of table B. I want to add the missing entries from B into A based on the values in another column, say column 2 of table A. However, not all the same entries are present in the two tables for the key.</p><p>For example, the two tables look like this:</p><p> </p><p>A = table({'John','Jane','Jim','Jerry','Jill'}',[1;2;1;3;1], {'', '', '', 'Mat',''}', ...</p><p> 'VariableNames',{'Employee' 'Department', 'Manager'})</p><p> </p><p>B = table([1 2]',{'Mary' 'Mike'}',...</p><p> 'VariableNames',{'Department' 'Manager'})</p><p> </p><img src = "http://www.mathworks.com/matlabcentral/answers/uploaded_files/20236/329b94f87524c45dee14f69d4dde6005.png"><p>If I try using the "join" function, I get an error because there are more Departments in A than in B.</p><p>
>> join(A,B)</p><p>Error using table/join (line 128)</p><p>The key variables for A and B cannot contain any missing values.</p><p>
How can I do this?</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/1607322014-10-30T18:45:48Z2014-10-30T18:45:48ZConfocal Algorithm for breast cancer detection<p>I have a code from link in which last few pages have code</p><p><a href = "http://etheses.dur.ac.uk/3531/1/MSCR_Zubaida_Thesis.pdf">http://etheses.dur.ac.uk/3531/1/MSCR_Zubaida_Thesis.pdf</a></p><p>In this they have used</p><p>function ConfocalAlgorithm(With,Without,Frequency)</p><p>but (With,Without,Frequency) is not specified</p><p>can anyone tell what are these 3 inputs,else is tere any code for this algorithm</p>nkumar/matlabcentral/answers/contributors/3941207-nkumartag:www.mathworks.com,2005:Question/1606652014-10-30T08:01:26Z2014-10-30T18:39:13ZQuestion to MATLAB profiler and speed of code<p>Hello dear MATLAB community,</p><p>I have a question concerning this piece of code</p><img src = "/matlabcentral/answers/uploaded_files/20201/Speed%20up.png"><p>This will calculate a piecewise cubic spline for my parametrized function. It is calles so often because it´s inside an optimization routine (fmincon).
My first question is: Is there a way to speed up this code?
And the second question: Why is the runtime of line 11 and 13 and 12 and 14 so different? Both lines are doing the same operation but the the calculation time differs around 30%?</p><p>Thanks for your help,</p><p>David</p>David/matlabcentral/answers/contributors/4226882-david