http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-03-06T12:34:26Ztag:www.mathworks.com,2005:Question/1818302015-03-06T12:20:10Z2015-03-06T12:34:26Z3D Plot With Different Colors for each Class<p>Hi,</p><p>I have a a set of points I would like to plot in a 3D space.</p><p>They are represented as: [x1 x2 x3 ... xn ; y1 y2 y3 ... yn] hence making it a 2xn matrix</p><p>I then have a n*1 vector containing class labels.</p><p>Right now, I am plotting them in a 2D space using:</p><pre class="language-matlab">gscatter(new_data(1,:),new_data(2,:),trainlabels,[],'<x+*sdv^o>ph.')
</pre><p>However, I would now like to add a third dimension making my data matrix a 3xn matrix. Is there any way I can obtain a result similar to gscatter but in three dimensions?</p><p>Thanks! :)</p>DarioGeShhttp://www.mathworks.com/matlabcentral/profile/authors/6249307-dariogeshtag:www.mathworks.com,2005:Question/1818322015-03-06T12:33:55Z2015-03-06T12:33:55Zop-amp inverter on simulink<p>Hello,</p><p>I'm trying to make a simple op-amp inverter on simulink but I dont know why my input is not square. I think I don't know what my "Solver Configuration" parameters should be. When I check the "Use local solver" in the Solver Configuration Parameters I can see a square pulse but doesn't start from zero time.</p><p>Please point my mistake or explain why it's supposed to be like this..</p>Conhttp://www.mathworks.com/matlabcentral/profile/authors/5736533-contag:www.mathworks.com,2005:Question/1818242015-03-06T11:21:29Z2015-03-06T12:31:39ZPlotting the heat equation using the explicit method<p>Hi, I am supposed to use the explicit method to plot an approximation of the heat equation in Matlab. The heat equation is as follows:</p><p>du/dx=d^2u/d^2x (u_t=u_xx).</p><p>Initial conditions:
u(x,0)=1 if x>0, while if x is equal or greater than zero u(x,0)=0.</p><p>The explicit method is the following: u(j,m+1) =r*u(j-1,m) + (1-2*r)*u(j,m)+r*u(j+1,m), where u is the solution, j is which x-value while m is which time value it is.</p><p>The matlab-code is the following:</p><p>L = 2.; % Length of the bar</p><p>T =0.1; % Time</p><p>maxm = 2000; % Time steps</p><p>dt = T/maxm;</p><p>n = 70; % Distance steps</p><p>dx = L/n;</p><p>r = dt/(dx^2); % Stability parameter, r less or equal to 1/2</p><p>for j=1:n+1</p><pre> x(j)=(j-1)*dx; %Because j actually starts at zero</pre><pre> if x> 0</pre><pre> u(j,1)=1;</pre><pre> else</pre><pre> u(j,1)=0;</pre><pre> end</pre><p>end</p><p>for m=1:maxm % Time Loop</p><p>for j=2:n; % Space Loop</p><p>u(j,m+1) =r*u(j-1,m) + (1-2*r)*u(j,m)+r*u(j+1,m);</p><p>end</p><p>end</p><p>figure(2)</p><p>plot(x,u(:,1))</p><p>I am not sure what is wrong. When I plot this, it equals zero for all x-values. It was supposed to be equal to 1 when x>0, while zero when x was less than zero. Can anyone help me to figure out was is wrong with this Matlab-code?</p><p>David</p>Davidhttp://www.mathworks.com/matlabcentral/profile/authors/3623264-davidtag:www.mathworks.com,2005:Question/1817682015-03-06T02:50:57Z2015-03-06T12:30:49ZSaving a preallocated matrix within a nested for loop<p>Code is below. I am trying to save the SpectroBey matrix preallocated before the nested loop to correspond with the files that are being pulled in within the first loop. So in the end, I would like to have saved SpectroBey1, SpectroBey2, Spectrobey3....and so on.</p><p>for j=1:6</p><pre> address=['Bey1_',num2str(j),'.wav']</pre><pre> y=audioread(address);
y=y(1:100:end,1)';
Fs=length(y)/5;
t2=(1:length(y))/Fs; t=t2(1:end-1);
y=y(1:end-1);
L=t2(end); n=length(y);
k=(2*pi/L)*[0:n/2-1 -n/2:-1]; ks=fftshift(k); </pre><pre> P=y;
Pf=fft(P);
width=100;
tslide=0:.1:L; </pre><pre> SpectroBey=[];
for jj=1:length(tslide)
g=exp(-width*(t-tslide(jj)).^2);
Pg=g.*P; Pgf=fft(Pg);
SpectroBey=[SpectroBey;abs(fftshift(Pgf))];
end
[m,n]=size(SpectroBey);
SpectroBey=reshape(SpectroBey,m*n,1);</pre><pre> save SpectroBey
end</pre>jpershttp://www.mathworks.com/matlabcentral/profile/authors/6038475-jperstag:www.mathworks.com,2005:Question/1818282015-03-06T12:17:08Z2015-03-06T12:26:12ZStopping the neural network by tr.gradient<p>In training an ANN using FITNET , I noticed , the tr.gradient gives a row matrice that the number of columns are the number of iterations , and the last column is the gradient reported on the train window</p><p>I tried doing :</p><pre class="language-matlab">for h=Hmin:dH:Hmax
j = j+1
net = fitnet(10);
net = init(net); % Improving Results since we use patternet we should use init
[ net tr y ] = train( net, x, t );
e = gsubtract(t,y);
performance = perform(net,t,y)
</pre><pre> if tr.gradient(end) < 0.05
tr.stop
end</pre><p>but it only stops the Validation test , not the actual training test , is there a way to do this ? and also when I retrain after a gradient like 0.503 and I get a smaller gradient , if from my outputs one is calculated not so precisely , the only thing happens is that , another output will be unprecise.</p><p>I have 8 inputs and 3 outputs</p>farzadhttp://www.mathworks.com/matlabcentral/profile/authors/2231846-farzadtag:www.mathworks.com,2005:Question/1817762015-03-06T03:47:02Z2015-03-06T12:26:08ZUse ode45 solve a Nonlinear Springs problem.<p>I don't know how to use ode45, can anyone help me with this problem?</p>Rayhttp://www.mathworks.com/matlabcentral/profile/authors/5859727-raytag:www.mathworks.com,2005:Question/1818312015-03-06T12:23:50Z2015-03-06T12:23:50ZXcode can not find tmwtypes.h file from code generated using Matlab Coder<p>I've translated a Matlab algorithm using Matlab Coder. I am in the process of integrating it into a dummy Xcode project. I'm getting the following error:</p><p>"tmwtypes.h" file not found</p><p>When I searched through the generated code I did confirm that no such file was generated. When I commented out the line, the same issue emerged for:</p><ul><li>"mex.h"</li><li>"emlrt.h"</li></ul>Ramon Andinohttp://www.mathworks.com/matlabcentral/profile/authors/6038749-ramon-andinotag:www.mathworks.com,2005:Question/1817802015-03-06T04:17:13Z2015-03-06T12:22:59Zhow can i add noise in particular place of the sine wave?<p>i want to add noise in the middle of the sine wave. but if i use the rand() function it adds noise to the total signal.how to add noise in some parts of the signal only.kindly help me.......</p>suganya saravananhttp://www.mathworks.com/matlabcentral/profile/authors/5528158-suganya-saravanantag:www.mathworks.com,2005:Question/1818292015-03-06T12:19:27Z2015-03-06T12:19:27ZHow to establish the tensile link of a tensegrity robot using SimMechanics?<p>I am a SimMechanics beginner. Recently, I want to construct a tensegrity robot model using SimMechanics. Can someone tell me how to establish the tensile link of a tensegrity robot using SimMechanics? The tensile link could be regarded as an elastic rope or rubber band. Many thanks!</p>Weibing Lihttp://www.mathworks.com/matlabcentral/profile/authors/6158636-weibing-litag:www.mathworks.com,2005:Question/1817772015-03-06T03:48:04Z2015-03-06T12:18:21Ztextread behaves differently when file resaved<p>Hello,</p><p>I have a not standard format (MRI scanner) file for which I use textread function to read the header.
When I use the following command directly on the file, I do not get the full content of the file:</p><p>textread('foo','%s', 'delimiter','\n','bufsize', 500000);</p><p>However, if I open the file in matlab text editor, make some change, save the file, undo the change and re save it, I get different output (which is correct).</p><p>I am assuming there is some problem with the format it was saved originally.</p><p>Can anyone help me understand this problem ?</p><p>Thanks,
Akshay</p>Akshay Jainhttp://www.mathworks.com/matlabcentral/profile/authors/4145555-akshay-jaintag:www.mathworks.com,2005:Question/1817612015-03-06T01:59:16Z2015-03-06T12:16:56ZProgramming Practices Tips - Index on matrix with some information<p>Hi,</p><p>I want a tip on what is the best way to code something.
I have a matrix with some information. The first column is the index number and the other columns are the informations (length, area, mass etc).</p><p>I would like to know if it is best to keep the first column or not. I mean, the index number is the number of row, so, instead of looking for the index number in the matrix and returning the proper information of the other columns, I just need to get the information on that row.
However, I was told I could keep the index numbers because if I change my input, I don't need to rewrite the input, but I will have to look for the index number in the matrix.</p><p>Which one is the best? Keep the index numbers and do the research every time or use the rows numbers to find the information?</p><p>Thanks</p>Thaleshttp://www.mathworks.com/matlabcentral/profile/authors/5301078-thalestag:www.mathworks.com,2005:Question/1818272015-03-06T12:16:33Z2015-03-06T12:16:33Zgui matrix getSelected index<p>Hello
i try to make a gui calendar and i have a question. The dates of the month it will be displayed by a matrix gui but i want to get the what index of the matrix the user has select
i tried get(handles.matrix ,'selected ' ); but the result is not what i want</p><p>matrix is the gui table</p><p>thank you</p>georgehttp://www.mathworks.com/matlabcentral/profile/authors/4868587-georgetag:www.mathworks.com,2005:Question/1817352015-03-05T19:19:59Z2015-03-06T12:11:15ZHow can I use same color range on subimages?<p>Hi,
I want, that my all subimages have the same colour range. I´m using caxis command but it doesn´t work. Can you help me? I'm lost.
(sorry for my english)</p><pre class="language-matlab">bottom = min(min(min(mmin1,mmin2),mmin3),mmin4);
top = max(max(max(mmax1,mmax2),mmax3),mmax4);
</pre><pre class="language-matlab">subplot(3,2,1+2)
subimage(imresize(imag,20),colormap(jet));
</pre><pre class="language-matlab">axis off
caxis manual
caxis([bottom top]);
colorbar;
</pre><pre class="language-matlab">subplot(3,2,2+2)
subimage(imresize(imag,20),colormap(jet)),
axis off
caxis manual
caxis([bottom,top]);
colorbar;
</pre>Ludmila Nemsilajovahttp://www.mathworks.com/matlabcentral/profile/authors/6249417-ludmila-nemsilajovatag:www.mathworks.com,2005:Question/1817312015-03-05T18:40:42Z2015-03-06T12:08:40ZWavelet Covariance Transform code in Matlab<p>Can someone please give a link to code/flowchart for executing Wavelet covariance transform of a function in matlab?
Thanks</p>Santino Mhttp://www.mathworks.com/matlabcentral/profile/authors/3055532-santino-mtag:www.mathworks.com,2005:Question/1818182015-03-06T09:54:17Z2015-03-06T12:00:13ZSolving a formula in Matlab<p>Hello everyone,</p><p>In the following formula : <b>X= 2y + 10 log(1+ E/S)</b></p><p>I want the user to input X, y, and S. Is there anyway i can get matlab to give me the value of E without having to rewrite the formula?</p><p>Thank you so much!</p>Belal Abboushihttp://www.mathworks.com/matlabcentral/profile/authors/5985841-belal-abboushitag:www.mathworks.com,2005:Question/1817732015-03-06T03:42:39Z2015-03-06T11:58:10ZHow to connect PS Product <p>i would like to multiple 2 signals, but i went to do some research, the only block to do it is (PS Product) <a href = "http://www.mathworks.com/help/physmod/simscape/ref/psproduct.html">http://www.mathworks.com/help/physmod/simscape/ref/psproduct.html</a></p><p>please help</p>billyhttp://www.mathworks.com/matlabcentral/profile/authors/4618034-billytag:www.mathworks.com,2005:Question/710992013-04-08T19:28:26Z2015-03-06T11:53:09ZImshow on Parallel Computing Toolbox<p>I am converting my code to utilise the Parallel Computing Toolbox and I am getting a peculiar error in an imshow instruction:</p><p>Error using imshow (line 209)
IMSHOW unable to display image.</p><p>Error in GPUDemo (line 9)
parfor (HSize = 1:n);</p><p>Caused by:
Error using imshow (line 209)
IMSHOW unable to display image.</p><p>line 209 of Imshow is the error message:</p><p>if ~images.internal.isFigureAvailable()
error(message('images:imshow:needJavaFigure'));
end</p><p>The error appears only when I use the matlabpool.</p><p>Obviously I am using many pools in order to have each pool applying a different value for a parameter (eg. HSize or Sigma in an imfilter) to the image</p><p>So I cant quite get the Aprils fool joke here: <a href = "http://blogs.mathworks.com/steve/?s_cid=global_nav">http://blogs.mathworks.com/steve/?s_cid=global_nav</a> :(</p><p>Thank you.</p>Dimitris Vayenashttp://www.mathworks.com/matlabcentral/profile/authors/3539619-dimitris-vayenastag:www.mathworks.com,2005:Question/1817452015-03-05T20:57:11Z2015-03-06T11:48:51ZCan't Launch Matlab R2010a Student Version on Mac OS X Yosemite 10.10.2<p>Dear Users, I need an urgent help as I've to code tonight.
I Can't Launch Matlab R2010a Student version on Mac OS X Yosemite 10.10.2.
He ask me to upgrade Java, but I've already updated it and still the same bug.
Any help around?
Dr. Hamad</p>hamadhttp://www.mathworks.com/matlabcentral/profile/authors/2528258-hamadtag:www.mathworks.com,2005:Question/1809422015-03-01T16:13:54Z2015-03-06T11:47:40Zhow can we fetch the count of the corners detected using detectMinEigenFeatures() function?<pre> i need to plot the graph based on the number corners detected in each frame and is it possible to fetch the number of corners detected using detectMinEigenFeatures()??</pre><p>points = detectMinEigenFeatures(rgb2gray(videoFrame));</p><p>Thanks in advance</p>athithyahttp://www.mathworks.com/matlabcentral/profile/authors/5444635-athithyatag:www.mathworks.com,2005:Question/1808372015-02-28T16:18:18Z2015-03-06T11:43:24ZSpeed up distance calculation in N-dimensional space <p>Hi all,</p><p>I have a function I'd like your help to speed up. The function takes two vectors x and Y of points in N-dimensional space as inputs (x and Y have the same size, typically N=500 by m=50,000). For every point in x I want to find the closest (according to squared difference) point in Y and return its number. The inputs are almost random. The function is :</p><pre class="language-matlab">function I = findnearest(x,Y)
I = zeros(size(x,1),1);
o = ones(size(Y,1),1);
for i = 1:size(x,1)
sqdiff = (o*x(i,:) - Y).^2;
xdiff = sum(sqdiff,2);
[~,I(i)] = min(xdiff);
end
end
</pre><p>I've tried to vectorize it but it turns out even slower than the current version. Any ideas on how to improve performance would be greatly appreciated! The function is called upon many times and as such takes immense computational time.</p><p>Thanks in advance!</p><p>Edit: I just realized that the part of the code that takes 99% of the time I only have N=5 to N=20... I'm terribly sorry for this confusion! The parts where N>=400 are not run that often so they are not that big a deal.</p>Anders Österlinghttp://www.mathworks.com/matlabcentral/profile/authors/1626944-anders-osterlingtag:www.mathworks.com,2005:Question/1818232015-03-06T10:58:54Z2015-03-06T11:42:56ZHow can I add a vertical line on an image plotted on an axes on MATLAB GUI<p>Hi, I am making a GUI that can browse image from directory and load it on an axes (and the user can rotate the image). I need to add a vertical line at the center of the image (preferably using button). But I am really lost here as I am new at MATLAB. So far, I can only make a GUI that can browse image and show it on an axes, and user can already rotate it using slider. Please tell me what to do to add the line using button. (Btw, I was trying to put my code here but it came out messy, anyone knows why?) Thanks a lot</p>Haidarhttp://www.mathworks.com/matlabcentral/profile/authors/6252560-haidartag:www.mathworks.com,2005:Question/1818262015-03-06T11:36:50Z2015-03-06T11:36:50ZTrouble with newmark method code. its not working and i don't know why. I want to get u,v and a from these equations<p>Could someone please help. I am trying to write a code for the new mark method but its not working and i can't figure out why.</p><p>%Time
ti=0;
dt=0.02;
tf=5.98;
t=ti:dt:tf;
nt=length(t);</p><p>%force
for t=0:0.02:6
p0=[0;0;0;132482]*t
p1=p0+[0;0;0;2649.64]
end</p><p>%Constants
alpha=0;
beta=0;
a1=alpha+(1/(0.5*dt));
b=beta+(0.5*dt);
c=0.5*dt;
d=(1-0.5)*dt;
e=1/0.5;
f=beta-((1-0.5)*dt);
g=1/(0.5*dt);
h=(1-0.5)/0.5;</p><p>%Initial conditions
u(:,1)=zeros;
v(:,1)=zeros;
a(:,1)=zeros;</p><p>MM=[1044,0,0,0;0,733.46,0,0;0,0,457.8,0;0,0,0,44.67];
KM=[9900000000,-9893000000,0,0;0,10000000000,-439000000,0;0,0,1370000000,-932200000;0,0,-932200000,932200000];</p><p>%time step
for it=1:nt-1
for t=1:nt-1
p0=[0;0;0;132482]*t;
p1=p0+[0;0;0;2649.64];
end
u(:,it+1)=((c*p1)+(d*p0)+(a1*MM*u(:,it))+(e*MM*v(:,it))+(f*KM*u(:,it)))./((a*MM)+(b*KM))
v(:,it+1)=g*(u(:,it+1)-u(:,it))-(h*v(:,it))
a(:,it+1)=g*(v(:,it+1)-v(:,it))-(h*a(:,it))</p><p>end</p>laura dolan http://www.mathworks.com/matlabcentral/profile/authors/6240571-laura-dolantag:www.mathworks.com,2005:Question/1818152015-03-06T09:28:38Z2015-03-06T11:34:39Zhow to calculate Block orientation feature in a image ?<img src = "/matlabcentral/answers/uploaded_files/26621/Untitled.png">ben austinhttp://www.mathworks.com/matlabcentral/profile/authors/6252458-ben-austintag:www.mathworks.com,2005:Question/296802012-02-20T14:54:46Z2015-03-06T11:30:01ZWarning: Integer operands are required for colon operator when used as index <p>I am using fft functions and have twice in my code this warning message, bu no clue why I get the warning:</p><pre class="language-matlab">N = 2048*16;
sizeData = size(data,2);
padding = (N-sizeData)/2;
</pre><pre class="language-matlab">cInput = zeros([1 N]); % <-- Warning
cInput(padding+1:(padding+sizeData)) = data;
cInput = fftshift(cInput);
</pre><pre class="language-matlab">% transform
cfourier = fftshift(fft(cInput));
</pre><pre class="language-matlab">% iFFt
cOutput = ifft(ifftshift(cfourier));
cOutput = ifftshift(cOutput); % <-- Warning
AmpIFourier = abs(cOutput(padding+1:(padding+sizeData)));
</pre>Matthias Pospiechhttp://www.mathworks.com/matlabcentral/profile/authors/2345824-matthias-pospiechtag:www.mathworks.com,2005:Question/1818252015-03-06T11:22:55Z2015-03-06T11:22:55ZCould nor read classpath.txt<p>Hi,</p><p>I have problems to start MATLAB R13. I see the following error:</p><p>'Could not read classpath.txt'</p><p>I actually don't have a file with this name, but a folder with this name.
I have installed JAVA.</p><p>Thank you,
Mariya</p>Mariya Popovahttp://www.mathworks.com/matlabcentral/profile/authors/1349023-mariya-popovatag:www.mathworks.com,2005:Question/1818212015-03-06T10:38:12Z2015-03-06T11:17:17Zsimple question about cell array resizing<p>Just a simple question:</p><p>I have</p><pre class="language-matlab">A={[1,2]';[3,4,5,6]'}'
</pre><p>and want to transform it into a cell array:</p><pre class="language-matlab">A={[1,2,3,4,5,6]'}'
</pre><p>which is the fastest way to get it?</p><p>Thanks</p>ludvikjahnhttp://www.mathworks.com/matlabcentral/profile/authors/4407571-ludvikjahntag:www.mathworks.com,2005:Question/1817382015-03-05T19:41:35Z2015-03-06T11:05:06ZHow to adapt my for loop to get it working with parfor? (ODE solver)<p>Hello,</p><p>Ive come a long way with programming as a newbie in Matlab, but now Im really stuck. Ive tried to 'slice' the variable dy, but unfortunately it didnt work. I guess the problem lies in the fact that i is dependent on SACn. Ive done this because the ODE solver needs a vector as input, not a matrix. Can someone please help me?</p><p>This is a snippet of code:</p><pre class="language-matlab">parfor SACn=0:SACnum-1
i=19+SACn*200:1:66+SACn*200;
dy(i-18+100,:) = alpha.*(1-y(i-18+100,:)).*(1./(1+exp(-((y(i,:) -th1)./k1))))-beta.*y(i-18+100,:);
dy(i-18+150,:) = alpha.*(1-y(i-18+150,:)).*(1./(1+exp(-((y(i-18+100,:)-th2)./k2))))-beta.*y(i-18+150,:);
end
</pre><p>I tried something like this (didnt work though):</p><pre class="language-matlab">parfor SACn=0:SACnum-1
temp1dy=zeros(1,200);
temp2dy=zeros(1,200);
for i=19:1:66
temp1dy(i-18+100,:) = alpha.*(1-y(i-18+100,:)).*(1./(1+exp(-((y(i,:) -th1)./k1))))-beta.*y(i-18+100,:);
temp2dy(i-18+150,:) = alpha.*(1-y(i-18+150,:)).*(1./(1+exp(-((y(i-18+100,:)-th2)./k2))))-beta.*y(i-18+150,:);
end
dy(i-18+100+SACn*200,:)=temp1dy;
dy(i-18+150+SACn*200,:)=temp2dy;
end
</pre><p>Additional info: I have vectorized my code in an ODE solver of Matlab, these are all the :) 's you see at the end of all variables such as y(i+18-100,:). Ive done this so that the ODE solver computes multiple values of dy for the same time point in parallel and then chooses the best option.</p><p>Please do not hesitate to ask for more details!</p>Sannehttp://www.mathworks.com/matlabcentral/profile/authors/5814245-sannetag:www.mathworks.com,2005:Question/1815292015-03-04T15:40:40Z2015-03-06T11:04:53ZToolbar Guide GUI Editor - Tool Creation - Brush<p>How can I include a brush tool onto my GUI? This is as far as I get</p><pre class="language-matlab">function uitoggletool_ClickedCallback(hObject, eventdata, handles)
</pre><pre> brush(handles.clean_plot)</pre><pre class="language-matlab">guidata(hObject, handles)
</pre><p>Many thanks,
Will</p>Williamhttp://www.mathworks.com/matlabcentral/profile/authors/5011478-williamtag:www.mathworks.com,2005:Question/1818082015-03-06T08:51:28Z2015-03-06T11:03:16Zhow to create a loop function<p>first of all I am new in matlab.
And I have a code like this:</p><pre class="language-matlab">k=1.4; z=200
</pre><pre class="language-matlab">for i=330:-1:6;
for j=330:-1:6;
x(i)=i;
y(j)=(x(i-1)/x(i))^((k-1)/k)*z;
%now I want to repeat this such as
y(j-1)=(x(i-2)/x(i-1))^((k-1)/k)*y(j);
end
end
</pre><p>can anyone tell me how to correct this??
thx a lot</p><p>[EDITED, Jan, Please apply code formatting - Thanks]</p>Alexandruhttp://www.mathworks.com/matlabcentral/profile/authors/4048923-alexandrutag:www.mathworks.com,2005:Question/1810362015-03-02T07:25:45Z2015-03-06T10:59:47Zhow to read the parameter and parameter value from the text file <p>Hii everyone..
I want to know how to read the text file which contains a variable and its value and then can be used somewhere in the program of .m matlab file...
for eg..
example.txt is the text file... whcich contains like this...
110.01 voltage 230 volts
110.02 Current 1.094 amps</p><p>now I want to read 110.01 & 110.02 as variable and 230 & 1.094 as their values respectively... but these values present in somewhere in the text... how to identify these parameters and their values...
please anyone suggest the command which I have to use for the above said problem</p><p>regards
Madhu</p>madhu T Shttp://www.mathworks.com/matlabcentral/profile/authors/5743976-madhu-t-stag:www.mathworks.com,2005:Question/1815692015-03-04T19:07:33Z2015-03-06T10:57:58ZFill the interior of a cylinder surface - SURF - generated by parametric equations<p>I've generated a cylinder using the parametric equations:</p><pre class="language-matlab">u = linspace(0,2*pi,50);
v = linspace(0,2*pi,50);
[u,v] = meshgrid(u,v);
</pre><pre class="language-matlab">x = cos(u);
y = sin(u);
z = v;
</pre><p>where u and v are 0-pi.</p><p>I've got a plot surf(x,y,z) of this cylinder and I want to fill all the interior points. Does anyone know how I can do this?</p><p>How can I do this?</p>Williamhttp://www.mathworks.com/matlabcentral/profile/authors/5011478-williamtag:www.mathworks.com,2005:Question/1818222015-03-06T10:39:24Z2015-03-06T10:39:24ZSTOP SENDING ME E-MAIL<p>I Already remove my e-mail from your mailing list several times!!!!!</p><p>CAN YOU PLEASE REMOVE ME FROM YOUR MAILING LIST???? !!!!!</p><p>Thanks.</p>giuseppehttp://www.mathworks.com/matlabcentral/profile/authors/4856878-giuseppetag:www.mathworks.com,2005:Question/1818202015-03-06T10:32:40Z2015-03-06T10:32:40ZHow dist function works??<p>If w=rand(4,3);
p=rand(3,1);</p><p>z=dist(w,p)</p><p>ans is
0.4278
0.6786
0.3725
0.6324
how these values comes?</p>Archana Goyalhttp://www.mathworks.com/matlabcentral/profile/authors/6252652-archana-goyaltag:www.mathworks.com,2005:Question/1817602015-03-06T01:57:45Z2015-03-06T10:24:28Zrenaming variable loaded from a file<p>Hello,
I have 4 .mat files including tens of variables of the same name. How I can rename the variables after loading each file in a new script file. I have read similar link but didn't work well.</p><p>Thanks</p>Reza Shttp://www.mathworks.com/matlabcentral/profile/authors/6251335-reza-stag:www.mathworks.com,2005:Question/1815962015-03-05T00:53:35Z2015-03-06T10:24:02ZFinding the approximate length with for loop?<p>mylength(f,g,a,b,n) which takes five inputs:
f: A function handle.
g: A function handle.
a: A real number.
b: A real number.
n: A positive integer.
Note: You may assume that that a < b.
Question: The functions f(t) and g(t) determine the location of an object at any time t by (f(t), g(t)).
Approximate the distance traveled by the object between t = a and t = b by dividing [a, b] into n equal
subintervals, determining the location of the object at each of those t-values and then by finding the
straight-line distance between those locations and adding them.</p><p>Code:</p><pre> function results = mylength(f,g,a,b,n);
totalLength = 0;
interval = sqrt((f-a)^2+(g-b)^2);
for x = [a:interval:b]
if x<b
totalLength = totalLength + x + interval;
end
end
results = totalLength;
end</pre><p>Error: I am getting an error at the start of the for loop. I know I am getting that error because in interval I am using 4 variables and not just 2 variables. Also an error with how I am calculating interval. Can someone help/tell me how I would adjust the code to solve for this problem.</p>Bradley Sanchezhttp://www.mathworks.com/matlabcentral/profile/authors/6106580-bradley-sancheztag:www.mathworks.com,2005:Question/1809102015-03-01T10:38:21Z2015-03-06T10:23:36Zaxes through origin in Matlab 2014b<p>Hi,
I'm searching for a possibility to set the x-axis through the origin in a 2D-plot in the 2014b version?
Can someone help me as the command 'oaxes' is not working anymore?</p>Janina Koussevhttp://www.mathworks.com/matlabcentral/profile/authors/5243840-janina-koussevtag:www.mathworks.com,2005:Question/1817962015-03-06T06:48:11Z2015-03-06T10:22:34ZQuestion on reshape function.<p>My code is as follows:</p><p>MS = perform_steerable_transform(rgb2gray(im), 3);</p><p>imageplot({MS{1:6}}, '', 2,3);</p><p>This code however returned an error of: Error using reshape
Size arguments must be real integers.</p><p>I am not sure what to change to make it real integers. This works when image was 'lena'. Why is it not working in other images?</p>lim -http://www.mathworks.com/matlabcentral/profile/authors/6012742-limtag:www.mathworks.com,2005:Question/1817892015-03-06T05:53:44Z2015-03-06T10:21:44Zreducing decimals and using as string<p>Hello,</p><p>I am going to truncate or round the decimals of a variable to the maximum of 2 decimal and then use num2str to shown the resulted number on a plot title. I am getting the error message when I use round()? Also I am not sure how to use fprint in this case. Any body can help please or any better solution?</p><p>Thanks</p>Reza Shttp://www.mathworks.com/matlabcentral/profile/authors/6251335-reza-stag:www.mathworks.com,2005:Question/1817152015-03-05T17:12:20Z2015-03-06T10:21:20Zautomatic headlining of uicontrol<pre> Hi everyone.</pre><pre> Is there any solution for automatic headlining of uicontrol('Style', 'edit')? Now I'm using two uicontrols: the first one is uicontrol('Style', 'edit') and the second one is uicontrol('Style', 'text') for headlining. Sometimes it is not very convenient. Any ideas? </pre>Vladhttp://www.mathworks.com/matlabcentral/profile/authors/5379792-vladtag:www.mathworks.com,2005:Question/1818172015-03-06T09:37:12Z2015-03-06T10:14:19ZHow can I solve a boundary value problem if besides a system of ordinary differential equations I have some algebraic ones?<p>I am trying to solve a system of ordinary differential equations. I have both initial and final conditions, so I consider it is a boundary-value problem. However, there are some parametres in the system that depend on the result of these equations, which leads to a system of equations of both differential and algebraic ones. I have tried to use bvp4c but I don't know hoy to introduce the algebraic equations.</p><p>I really appreciate any help.</p>Cristina Díazhttp://www.mathworks.com/matlabcentral/profile/authors/6195445-cristina-diaztag:www.mathworks.com,2005:Question/1817072015-03-05T16:41:08Z2015-03-06T10:14:11ZHow show variable number of cell's array in a message box?<p>Hi everyone,</p><p>I want a cell, which includes every time (depend on calculation) different number of array. It means, depend on calculation the number of arrays could be 2 or 3 etc. Now I want to show the content of this cell in a message box. I have written the following:</p><p>%X_AP_Name is the cell with variable number of arrays</p><pre class="language-matlab">msgbox(sprintf('Please insert *.txt-data of %s in folder sample',X_AP_Name{:}))
</pre><p>but the text before and after arrays of cell is repeated according to number of arrays. If for example Size(X_AP_Name)=2, it result in following text:
"Please insert *.txt-data of A in folder samplePlease insert *.txt-data of B in folder sample"</p><p>But i want to have "Please insert *.txt-data of A and B in folder sample"</p><p>what should I do?!</p>Mahdihttp://www.mathworks.com/matlabcentral/profile/authors/5863123-mahditag:www.mathworks.com,2005:Question/1818012015-03-06T08:08:28Z2015-03-06T10:10:49Zwhere I do download install_addon.m<p>when I use this command in the command window (matlab):
install_addon('smlink.r2013a.win64.zip')
The following error occurs:
Undefined function 'install_addon' for input arguments of type 'char'.</p><p>I know i have to download the install_addon.m file, but I do not know where I can.
plz help me.
Thank you</p>Youssof Shamadihttp://www.mathworks.com/matlabcentral/profile/authors/6252230-youssof-shamaditag:www.mathworks.com,2005:Question/1817112015-03-05T17:02:34Z2015-03-06T10:08:13ZReverse boundary conditions in a one-dimensional degenerate PDE<p>I want to solve a PDE with convection and diffusion, which has travelling waves solutions which go from 1 to 0 and travel from left to right as the picture attached. It happens that this equation also has the same solutions but travelling from right to left and going from 0 to 1 (like the attached picture, the last profile from right to left is the first one).</p><p>To obtain the normal (left to right) profiles the initial conditions could be for example a step function or a tanh. The boundary conditions are u(xl,t)=1 and u(xr,t)=0. This is how I code this:</p><p>function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = ur;
qr = 0;</p><p>If I want to obtain the right to left profiles, strictly speaking I only need to "reverse" the boundary and initial conditions appropriately. That is, for example a –tanh (instead of +) and something like: u(xl,t)=0 and u(xr,t)=1. This is how I changed it:</p><p>function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ur;
ql = 0;
pr = ul;
qr = 0;</p><p>However this does not work, i get the following error:</p><p>Error using pdepe (line 293)
Spatial discretization has failed. Discretization supports only
parabolic and elliptic equations, with flux term involving spatial
derivative.</p><p>Error in test4 (line 50)
sol = pdepe(m,@pdex1pde,@pdex1ic1,@pdex1bc,x,t);</p><p>which is weird because the normal case works fine (that is the normal case already had convection and density dependent diffusion), I think that I am not putting the BC properly.</p><p>I must add that I have been able to show that these type of waves are solutions using another numerical software (and by changing the initial and boundary conditions is how I obtained it). So it’s just a matter of coding the initial conditions properly I think.</p><p>If you have guys have any advise I will appreciate it vey much.</p><p>I am using Matlab_R2014a and the PDE solver is pdepe. I can send you my code if needed. Many thanks in advance.</p>J. PVhttp://www.mathworks.com/matlabcentral/profile/authors/1899648-j-pvtag:www.mathworks.com,2005:Question/1818192015-03-06T10:07:52Z2015-03-06T10:07:52ZHow to save all values generated from a for statement in different variables<p>Hello,</p><p>I'm using a for statement to extract values from a matrix depending on i.</p><p>for i=1:intn % number of sources
Ls= filename(i+1,5)</p><p>In this case, I need to save all generated values of Ls as Ls1, Ls2, Ls3, etc.. I tried Ls(i) but it didn't work. Does anyone know how to integrate i into the string name?</p><p>Any help would be highly appreciated!</p><p>Thanks,</p>Belal Abboushihttp://www.mathworks.com/matlabcentral/profile/authors/5985841-belal-abboushitag:www.mathworks.com,2005:Question/1817412015-03-05T20:12:49Z2015-03-06T10:05:17Zhow can I take a global variable declared in a program, take it in a function, change its value inside the fuction and give it again to the program as global?<p>Hi!
I have the following Problem:
I have a variable declared in my program, whose value I want to Change in a function and then return it to the program as global, so that when I call the function again the value stored in there is the one I calculated the last time within the function.
If anyone could help me, please...</p>studenthttp://www.mathworks.com/matlabcentral/profile/authors/6171979-studenttag:www.mathworks.com,2005:Question/1817242015-03-05T18:03:47Z2015-03-06T10:04:10ZHow to pass new values into the function called by ODE45?<p>Hi,</p><p>I am using a For loop to interrupt each step of the integration by ODE45 as follows:</p><pre> tspan = linspace(Tinit, Tend, 10);
T0 = [Tc,Tsk];</pre><pre> for i = 1:1:n
Anew = input(sprintf('Enter new of A: ',A));
if ~isempty(Anew);
A = Anew;
end</pre><pre> Bnew = input(sprintf('Enter new value of B: ',B));
if ~isempty(B);
B = Bnew;
end</pre><pre> Cnew = input(sprintf('Enter new value of C: ', C));
if ~isempty(Cnew);
C = Cnew;
end</pre><pre> [t,T] = ode45(@(t,T)Heat(t,T,Tc,Tsk), tspan, T0);</pre><pre class="language-matlab">end
</pre><p>The ode45 solver calls the function 'Heat', as follows:</p><pre> function heat = Heat(t,T,Tc,Tsk)</pre><pre class="language-matlab">Wt=65;
Ht=2;
Cbt=0.78;
</pre><pre> Ad = 0.202.*(Wt.^0.425).*(Ht.^0.725);</pre><pre> a = feval(@alpha, Tc,Tsk); %fraction of body surface area that is skin</pre><pre> TCCRA = ((1-a).*Wt.*Cbt)./Ad; </pre><pre> heatc = feval(@HSCR,Tc,Tsk);
Tcdot = heatc./TCCRA; %core temp rate equation</pre><pre> TCSKA = (a.*Wt.*Cbt)./Ad; </pre><pre> heatsk = feval(@HSSK,Tc,Tsk);
Tskdot = heatsk./TCSKA;</pre><pre> hcrsk = [Tcdot; Tskdot]; %vector of Tc and Tsk rate equations</pre><p>This function uses Tc and Tsk (input by the user before the For loop starts) to evaluate heatc (and heatsk) into a numerical value. HSCR and HSSK are functions called by heatc and heatsk respectively. Tcdot and Tskdot are rate equations to be solved by the ode.</p><p>The goal of using this ODE solver is to get the new values of Tc and Tsk, which also happens to be the inputs of the function called by the ode45 solver (@Heat). Hence, this affects the evaluation of heatc (and heatsk) within the Heat function, thus affecting the expressions of the rate equations, and I am guessing that this plays a role in the outputs (Tc and Tsk) of the ode solver.</p><p>Also, the motive for interrupting the ode at each step using the For loop is to prompt the user to input the values A, B and C which are inputs to other functions (not shown here) which will affect the numerical value of heatc and heatsk, thus the rate equations.</p><p>My question is, is there any way to pass updated values of Tc and Tsk after the previous integration step to the function (@Heat) in the next integration step, within the ODE solver?</p>Maxxyhttp://www.mathworks.com/matlabcentral/profile/authors/6175288-maxxytag:www.mathworks.com,2005:Question/1299342014-05-16T23:02:37Z2015-03-06T09:42:57ZCan I import history.m from 2013 to History.xml in 2014a?<p>Why OH why does Mathworks changes things that worked great in one version - I hate their new releases and the changes that simply frustrates how one is used to doing things.</p><p>For several releases now, I always copied my previous release's "history.m" file into the appropriate directory and I could go on with what I had done. Come 2014a, they decided to make the history into an XML file and I am now grinding my teeth in frustration, because I cannot simply use the up arrow and go with what I was doing before I updated to the new release. I have to keep the old history file open and copy and paste from there. I had my history set to 50,000, so I remembered some years of commands. Very helpful when I want to remember the set of commands I used on a specific day in the past.</p><p>Mathworks - your ribbon interface was a bad idea, now this history is a bad idea. Maybe it is time to abandon Matlab and find an alternate....</p>Matlab Challengedhttp://www.mathworks.com/matlabcentral/profile/authors/62281-matlab-challengedtag:www.mathworks.com,2005:Question/1817402015-03-05T20:11:31Z2015-03-06T09:40:51ZHow to implement contAcquireNChan.c example from National Instrument with a mex file in matlab 2014b in mac OS <p>I am trying to build a mex file to acquire data through a NIDAQ USB-6009 device but I am facing troubles when trying to compile the mex file. The NI drivers installed are the 14.0 version which supports 64 bits architecture according to NI (the example compiles and runs in a C Command Line Tool project in Xcode 6.1.1 on my computer)</p><p>Here is my code:</p><pre class="language-matlab">#include <math.h>
#include <matrix.h>
#include <mex.h>
#include "NIDAQmxBase.h"
#include <stdio.h>
#include <time.h>
</pre><pre class="language-matlab">#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }
</pre><pre class="language-matlab">void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// Task parameters
int32 error = 0;
TaskHandle taskHandle = 0;
char errBuff[2048]={'\0'};
int32 i,j;
time_t startTime;
bool32 done=0;
</pre><pre> // Channel parameters
char chan[] = "Dev1/ai0, Dev1/ai1";
float64 min = -10.0;
float64 max = 10.0;</pre><pre> // Timing parameters
char clockSource[] = "OnboardClock";
uInt64 samplesPerChan = 1000;
float64 sampleRate = 5000.0;</pre><pre> // Data read parameters
#define bufferSize (uInt32)1000
float64 data[bufferSize * 2];
int32 pointsToRead = bufferSize;
int32 pointsRead;
float64 timeout = 10.0;
int32 totalRead = 0;</pre><pre> printf("Example will halt automatically.\n");
DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,clockSource,sampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesPerChan));
DAQmxErrChk (DAQmxBaseCfgInputBuffer(taskHandle,200000)); //use a 100,000 sample DMA buffer
DAQmxErrChk (DAQmxBaseStartTask(taskHandle));</pre><pre> // The loop will quit after 10 seconds</pre><pre> startTime = time(NULL);
while( time(NULL)<startTime+10 ) {
DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize*2,&pointsRead,NULL));
totalRead += pointsRead;
printf("Acquired %ld samples. Total %ld\n",pointsRead,totalRead);
// Just print out the first 10 points of the last data read
for (i = 0; i < 10; ++i)
printf ("data0[%ld] = %f\tdata1[%ld] = %f\n",i,data[2*i],i,data[2*i+1]);</pre><pre> }
printf("\nAcquired %ld total samples.\n",totalRead);</pre><pre class="language-matlab">Error:
if( DAQmxFailed(error) )
DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
if(taskHandle != 0) {
DAQmxBaseStopTask (taskHandle);
DAQmxBaseClearTask (taskHandle);
}
if( DAQmxFailed(error) )
printf ("DAQmxBase Error %ld: %s\n", error, errBuff);
</pre><pre class="language-matlab">}
</pre><p>And the errors I get while compiling:</p><pre class="language-matlab">Error using mex
Undefined symbols for architecture x86_64:
"_DAQmxBaseCfgInputBuffer", referenced from:
_mexFunction in helloWorld.o
"_DAQmxBaseCfgSampClkTiming", referenced from:
_mexFunction in helloWorld.o
"_DAQmxBaseClearTask", referenced from:
_mexFunction in helloWorld.o
"_DAQmxBaseCreateAIVoltageChan", referenced from:
_mexFunction in helloWorld.o
"_DAQmxBaseCreateTask", referenced from:
_mexFunction in helloWorld.o
"_DAQmxBaseGetExtendedErrorInfo", referenced from:
_mexFunction in helloWorld.o
"_DAQmxBaseReadAnalogF64", referenced from:
_mexFunction in helloWorld.o
"_DAQmxBaseStartTask", referenced from:
_mexFunction in helloWorld.o
"_DAQmxBaseStopTask", referenced from:
_mexFunction in helloWorld.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
</pre>Antoinehttp://www.mathworks.com/matlabcentral/profile/authors/649317-antoinetag:www.mathworks.com,2005:Question/1818162015-03-06T09:32:58Z2015-03-06T09:32:58ZI have problem with serial send this is problem messege " Error evaluating registered method 'Start' of MATLAB S-Function 'sserialsb" Please help to solve it<img src = "/matlabcentral/answers/uploaded_files/26623/eror%20serial%20send.PNG">Anang sutawijayahttp://www.mathworks.com/matlabcentral/profile/authors/5989624-anang-sutawijayatag:www.mathworks.com,2005:Question/63392011-04-27T20:31:01Z2015-03-06T09:29:45ZCannot read serial port data with Matlab R2010a<p>I am trying to write a Matlab script for sampling voltage data from an Agilent 34401A digital multimeter over the serial RS232 connection. I am able to open the connection, write the SCPI commands, but I cannot read any responses from the multimeter. There are never any available bytes, and fscanf, fread, etc. do not find any data. Interestingly, the only way I have been able to receive data is over the Agilent Connection Expert Interactive IO interface. I have also tried the same SCPI commands in Python to no avail, as well as CoolTerm. But since it works in the Agilent software, I know it cannot be the driver, cable, or USB-serial converter I am using.</p><p>Here is the setup:</p><p>Matlab version R2010a
Agilent 34401A DMM
Belkin F5U109 USB-serial converter (with driver installed)
Windows Vista Basic
Agilent IVI/VISA drivers installed for the DMM</p><p>Here is the code that I am using to debug this issue:</p><pre class="language-matlab">serialObject = serial('COM4');
set(serialObject, 'BaudRate', 9600);
set(serialObject, 'Parity', 'none');
set(serialObject, 'ReadASyncMode', 'continuous');
set(serialObject, 'StopBits', 1);
set(serialObject, 'Timeout', 10);
set(serialObject, 'RequestToSend', 'off');
set(serialObject, 'FlowControl', 'none');
set(serialObject, 'Terminator', 'LF');
fopen(serialObject);
fprintf(serialObject, '*RST\n');
fprintf(serialObject, '*CLS\n');
fprintf(serialObject, '*IDN?\n');
pause(1);
fscanf(serialObject)
fclose(serialObject);
delete(serialObject);
</pre><p>At the fscanf() part it always times out and never finds data. I have checked this manually using serialObject.bytesAvailable as well.</p><p>I googled this problem for hours, finding at least a dozen reports of this issue but as of yet, I have not found a single solution. Can anyone help me with this dilemma? =[[[[[[[[ Thank you in advance.</p>Markhttp://www.mathworks.com/matlabcentral/profile/authors/1866155-mark