http://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2016-12-09T07:34:14Ztag:nl.mathworks.com,2005:Question/3159262016-12-08T05:31:32Z2016-12-09T07:34:14ZHow to plot a object boundary using MATLAB if we have coordinates?<p>Hello! Everyone,
I have Object placed inside a box and i used distance sensors to get the distance of the object from a reference point (0,0,0), now i want to plot the surface of this object using MATLAB, but i am confused, which plotting function to use.</p><p>Suppose the object placed is cylindrical object as shown below.</p><img src = "/matlabcentral/answers/uploaded_files/64989/Image.png"><p>These are the valid points which i get from the sensor from point (0,0,0) and all of these points are same across the z-axis</p><p>x = (89.26772163,89.2251516,89.17737906,89.05573047,
88.8611554,88.59463961,88.2572044,87.84990611,
90.60990337,93.38333305,96.16835842,98.96312702,
101.7657715,104.5744107,107.4709263)</p><p>y = (86.20483673,83.20379993,80.29567276,77.41496542,
74.56336272,71.74252458,68.95408524,66.19965255,
65.83194826,65.38771374,64.8663768,64.26740613,
63.59031171,62.83464514,62.04836823)</p><p>Which plot should i use to get the one side boundary using MATLAB as follow:</p><img src = "/matlabcentral/answers/uploaded_files/64999/Output.png"><p>With the points above, it is not possible to draw the complete image, but at-least it is possible to draw the boundary of the front side.
Please suggest which type of plot, surface plot i can use.</p>Arun Sharmahttp://nl.mathworks.com/matlabcentral/profile/authors/1852015-arun-sharmatag:nl.mathworks.com,2005:Question/3152242016-12-03T10:38:22Z2016-12-09T07:32:08ZError in Integral Equation <pre> y1 = int(Re*(L1+Re*t*tan(K))*sin(b1_1-t),t,0,b1_1)-...
int(Re*(L1+Re*t*tan(K))*sin(t-b1_1),t,b1_1,A)- ...
int(Re*a *sin(t-b1_1),t,A,B)-...
int(Re*(a-Re*(t-B)* tan(K)) *sin(t-b1_1),t,B,pi);
b1_1 = solve(y1==0,b1_1); </pre><p>Error：
solve (line 265)</p><p>Specify a variable for which you solve.</p><p>zsh11_hudu (line 32)</p><p>b1_1 = solve(y1==0,b1_1);</p>Scotthttp://nl.mathworks.com/matlabcentral/profile/authors/7322698-scotttag:nl.mathworks.com,2005:Question/3161332016-12-09T07:11:56Z2016-12-09T07:26:09ZCurve fitting f(x,y) result<p>i have data like-
x y
1 2
3 3
4 5
3 4
5 3
3 3
1 1
5 6
2 3
and i want fitting like</p><img src = "/matlabcentral/answers/uploaded_files/65100/fig.jpg">AKHILESH KUMARhttp://nl.mathworks.com/matlabcentral/profile/authors/9292568-akhilesh-kumartag:nl.mathworks.com,2005:Question/3160172016-12-08T15:11:30Z2016-12-09T07:24:09ZBoundary conditions with stiff problems<p>Hello, I'm trying to solve a system of PDEs that depends on space (1 dimension) and time. I want to solve it using a second order discretization in space and then using ode23s to solve the system of ODEs (method of lines).</p><p>The problem is that I have a laplacian operator and I can just integrate in the interior nodes (let's say from 2 to n-1). The values for nodes 1 and n depend on their neighbours and should be updated at each time step.</p><p>How could I set these restrictions to solver?</p><p>Here is the scheme:</p><pre class="language-matlab">function dydt = fun(t,u)
</pre><pre class="language-matlab">for j = 2:n-1
impose right hand side function
end
</pre><pre class="language-matlab">%Now I want to impose the value in y(1) and y(end)
</pre><pre class="language-matlab">end
</pre>Albert Jimenezhttp://nl.mathworks.com/matlabcentral/profile/authors/8725869-albert-jimeneztag:nl.mathworks.com,2005:Question/3161282016-12-09T05:48:52Z2016-12-09T07:19:19Zhow can i find the location of the largest element in a 2-D matrix not in a column or row matrix?<p>I was getting a 1080-by-1920 matrix and i have to find the location of the largest value of the matrix, so how can i find it. I have already found the largest value from that matrix, but couldnot trace it's location.</p>NAVNEET NAYANhttp://nl.mathworks.com/matlabcentral/profile/authors/8471441-navneet-nayantag:nl.mathworks.com,2005:Question/3161322016-12-09T07:00:09Z2016-12-09T07:00:09ZWhy is it Showing this error?<p>Write a function called integerize that takes as its input a matrix A of integers of type double, and returns the name of the “smallest” signed integer class to which A can be converted without loss of information. If no such class exists, the string 'NONE' is returned. For example, if the smallest element of A is -100 and the largest is +100, then the function would return 'int8'. As another example, if there is an element of A equal to -1e20, then the function would return 'NONE'.</p><pre class="language-matlab">if true
% code
end
function s=integerize(A)
if (A<=127 && A>=-128)
s='int8';
else if(A<=32767 && A>=-32768)
s='int16';
else if (A<=2147483647 && A>=-2147483648)
s='int32';
else if (A<9223372036854775807 && A>-9223372036854775808)
s='int64';
</pre><pre> else
s='NONE';
end;
* _Error: File: integerize.m Line: 6 Column: 10
At least one END is missing: the statement may begin here._*</pre>Varun Saxenahttp://nl.mathworks.com/matlabcentral/profile/authors/9302571-varun-saxenatag:nl.mathworks.com,2005:Question/3088082016-10-24T08:20:07Z2016-12-09T06:50:24ZI meet with a question,The Add-On Explorer is currently unavailable,who knows?thank you very much<p><b>bold</b></p>sheng duhttp://nl.mathworks.com/matlabcentral/profile/authors/6929775-sheng-dutag:nl.mathworks.com,2005:Question/3161292016-12-09T06:03:51Z2016-12-09T06:47:11ZHow to vectorize a specific for-loop<p>I am trying to vectorize the for-loop hereafter. Would you have any hint? Thank you</p><pre class="language-matlab">for i = 1 : numel(text)-k+1 % "text" is a string
pattern(i,:) = text(i:i+k-1);
end
</pre>Paolo Binettihttp://nl.mathworks.com/matlabcentral/profile/authors/86528-paolo-binettitag:nl.mathworks.com,2005:Question/3161052016-12-08T23:55:24Z2016-12-09T06:46:18ZMATLAB parallel loop with slight delays<p>I have a parallel loop in matlab shown below. Is there a way to make sure the loops are not running simultaneously but with a slight delay? I am open to use batch or spmd also but have limited knowledge of them and will appreciate any help. I am calling another program, myprogexe.exe, but this program needs to access a specific port on a pc and multiple requests cant go in. hence i need to make sure there is a very slight delay in requests. myprogexe.exe is a very computational heavy code itself (takes about 10 mins for each input to run)</p><pre class="language-matlab">parfor i=1:length(MinorRoots)
runmodels = MinorRoots{i};
cmd = ['$myprogexe -v 2014.2 ', runmodels];
[status, result] = system(cmd);
end
</pre>Re Khhttp://nl.mathworks.com/matlabcentral/profile/authors/3316790-re-khtag:nl.mathworks.com,2005:Question/3161302016-12-09T06:07:17Z2016-12-09T06:33:48ZGet a subset of a structure array in mex<p>Is it possible to get a subset of a structure array in mex? In other words, the mex equivalent of the following in Matlab:</p><pre class="language-matlab">s2 = s1(2:5); %s1 is a structure array
</pre><p>In my (current) use case, the structure array is empty, although fields have been defined.</p>Jim Hokansonhttp://nl.mathworks.com/matlabcentral/profile/authors/937359-jim-hokansontag:nl.mathworks.com,2005:Question/3161312016-12-09T06:33:26Z2016-12-09T06:33:26ZConverting matrix to binary matrix and then saving the matrix to excel<p>Hi.I want to export image matrix in binary format to excel,I have used dec2bin to covert my image matrix into binary format.The problem i am facing is that the dec2bin coverts the image matrxi into binary vector, i want the results in matrix form and then stored in the excel as rows and coloums.code is attached.</p><pre> A=imread('lena.tiff');
x=dec2bin(A,8)
xlswrite('bin.xlsx', cellstr(x))</pre>Hafeez Wolfhttp://nl.mathworks.com/matlabcentral/profile/authors/9334811-hafeez-wolftag:nl.mathworks.com,2005:Question/709342013-04-08T03:21:11Z2016-12-09T06:18:03ZHow to install Matlab Student version on Windows 8?<p>I would like to install the MATLAB student version on Windows 8. I have downloaded everything and when I click the installer to run, it goes to update Microsoft Visual C++2005, and then stops and nothing happens.</p><p>After reading some other forums, I have tried to uninstall Microsoft Visual C++2005, and have tried to run the installer in safe mode.</p><p>Please let me know what I can do to successfully install the program. Also note I am installing the 32 bit student version on a 64 bit computer (which math works says should be compatible).</p>Shannonhttp://nl.mathworks.com/matlabcentral/profile/authors/4212677-shannontag:nl.mathworks.com,2005:Question/3159302016-12-08T05:55:02Z2016-12-09T06:04:58Z AUTO CLUSTERING instead of setting the value of 'C' in Fuzzy C-Mean<p>I have a problem in FCM. i want it to be AUTO CLUSTERING instead of setting the value of 'C'?.
This is a normal FCM code that need manually set the C:
options = [NaN 100 0.001 0];
[centers,U,objFun] = fcm(data,3,options);</p>nur shidah ahmadhttp://nl.mathworks.com/matlabcentral/profile/authors/7062368-nur-shidah-ahmadtag:nl.mathworks.com,2005:Question/3158502016-12-07T17:18:11Z2016-12-09T05:38:22ZHow can I acquire frames from a live video stream, acquire the frames, then use the frames to recreate the live video stream?<p>Hello.
I want to detect red objects from the live video stream (I know how to detect red objects)</p><p>What I want to know is how to acquire the frames from the original live video stream and recreate another live video stream using the processed frames and play these two video streams side by side.</p><p>Please help. I'd be really grateful to you.</p>Shinobuhttp://nl.mathworks.com/matlabcentral/profile/authors/8401680-shinobutag:nl.mathworks.com,2005:Question/3157662016-12-07T06:44:29Z2016-12-09T05:36:59Zi want to concatenate two variable but getting an error..."Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have the same set of fields"<p>I want to concatenate two variables.
first i loaded my data which is a matrix, to both variables then store particular part of variables in another variable and then concatenate them.
Here is my code.</p><pre class="language-matlab">t=load('2');
v=load('3');
T.a =t(:,2:size(t,2));
c=v(:,2:size(v,2));
ans=cat(2,T.a,c);
</pre><p>Here '2','3' are my files.</p><p>but i am getting error...</p><p>Error using cat
Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that
these arrays have the same set of fields.</p><p>Error in Untitled3 (line 5)
ans=cat(2,T.a,c);
i think becoz when i load data it stores in variables with different field names.</p><p>Plz provide some solution . i have to use it</p>MAYANK RATHOREhttp://nl.mathworks.com/matlabcentral/profile/authors/8631616-mayank-rathoretag:nl.mathworks.com,2005:Question/3161082016-12-09T00:12:54Z2016-12-09T05:00:54ZHow can I use variables defined within a parent function in nested functions?<p>I have a parent function and 2 inner (nested) functions. Nested1 defines a differential equation. Nested2 defines another differential equation which is a function of the outputs of the first equation, but solved backwards in time.</p><p>I am able to use the variables of the parent function in Nested1, but not in nested2. In other words, the variables of the parent function are not read by Nested2. I need the variables defined in the parent function to be used in both inner functions.</p><p>Your help in this would be much appreciated.</p><p>Many thanks.</p><pre class="language-matlab">function parent
% I have defined some variables here
</pre><pre> [t,y]= ode45(@ode1_solve, tspan, Init_cond_1); %Solves the diff.eqn. of Nested1
[tau,x]= ode45(@ode2_solve, tspan1, Init_cond_2); %Solves diff.eqn. of Nested2</pre><pre> function Nested1 = ode1_solve(t,y)
%Differential equation1
end</pre><pre> function Nested2 = ode2_solve(tau,x,y)
%Differential equation2
end</pre><pre> end</pre>Karim Shawkihttp://nl.mathworks.com/matlabcentral/profile/authors/9335147-karim-shawkitag:nl.mathworks.com,2005:Question/3161262016-12-09T04:49:03Z2016-12-09T05:20:23ZHow to calculate a series of points without using loop statement? 25 points equally distributed along a total length<p>this is my code.</p><pre class="language-matlab">%length of bridge%
</pre><pre class="language-matlab">length_ft = input('Enter the length of the bridge[ft]: ');
</pre><pre class="language-matlab">%convert to inches%
</pre><pre class="language-matlab">l=length_ft*12;
</pre><pre class="language-matlab">%calculte deflection at 25 points evenly spaced%
</pre><pre class="language-matlab">point = l/25;
</pre><pre class="language-matlab">x = 0:l-point
</pre><p>I can only get 1 point than the rest of the points are in increments of 1. Ho.w can I make this so that whatever length input I am getting the correct increment? Beginner of matlab. Thank you</p>D Thttp://nl.mathworks.com/matlabcentral/profile/authors/9342402-d-ttag:nl.mathworks.com,2005:Question/3160392016-12-08T17:01:07Z2016-12-09T04:48:10ZGet mouse down and mouse up events from slider<p>I am implementing (in R2016a) a continuous slider using a listener as follows:</p><pre class="language-matlab">sld = uicontrol('Style', 'slider');
sld.addlistener('ContinuousValueChange', @(src, evt) callbk(src, evt));
</pre><p>What I also want to do is to have callbacks when the mouse is first clicked on the slider and then when it is released. I can't find any appropriate events to do this in the uicontrol class.</p><p>Does anyone have suggestions?</p>Etaoin Shrdluhttp://nl.mathworks.com/matlabcentral/profile/authors/6613323-etaoin-shrdlutag:nl.mathworks.com,2005:Question/2906712016-06-18T15:14:14Z2016-12-09T04:33:00ZAdd-On Explorer currently unavailable<p>When will Add-On Explorer will be unavailable again? The problem remains for more than 2 months. Is there an alternative solution? Our work falls behind because of that.</p><img src = "/matlabcentral/answers/uploaded_files/54525/add-on.jpg">K Ghttp://nl.mathworks.com/matlabcentral/profile/authors/7154783-k-gtag:nl.mathworks.com,2005:Question/3161252016-12-09T04:02:10Z2016-12-09T04:27:33ZI am trying to solve a system of nine equations and nine variables using the symbolic toolkit, and am getting an error message when trying to convert the solutions to a double array.<p>This is the code I have written:</p><pre class="language-matlab">if true
% code
end
one=sym('cosd(45.4)*G1+G2=0');
two=sym('-G9-cosd(46.5)*G8=0');
three=sym('1107.14+sind(46.5)*G8=0');
four=sym('4000=G7+sind(46.5)*G5');
five=sym('G9=cosd(46.5)*G5+G6');
six=sym('cosd(46.5)*G8=G4');
seven=sym('-sind(46.5)*G8-G7=500');
eight=sym('G4+cosd(46.5)*G5-cosd(45.4)*G1=0');
nine=sym('-G3-sind(46.5)*G5-sind(45.4)*G1=1000');
[G1,G2,G3,G4,G5,G6,G7,G8,G9]=solve(one,two,three,four,five,six,seven,eight,nine)
fprintf(['G1=%.3f;\nG2=%.3f;\nG3=%.3f;\nG4=%.3f;\nG5=%.3f;\nG6=%.3f;'...
'\nG7=%.3f;\nG8=%.3f;\nG9=%.3f\n'],double(G1),double(G2),double(G3)...
,double(G4),double(G5),double(G6),double(G7),double(G8),double(G9))
</pre><p>And this is the error I recieve:</p><pre class="language-matlab">if true
% code
end
Error using symengine
DOUBLE cannot convert the input expression into a double array.
</pre><pre class="language-matlab">if true
% code
end
Error in sym/double (line 613)
Xstr = mupadmex('symobj::double', S.s, 0);
</pre>Ryan Brownhttp://nl.mathworks.com/matlabcentral/profile/authors/8578434-ryan-browntag:nl.mathworks.com,2005:Question/3161112016-12-09T01:19:35Z2016-12-09T04:25:14ZHow do I Convert a plot in real time from radians to degrees?<p>Hi, I need to plot a graph in real time from radians to degrees. I attempted this:</p><p>plot(t(i),rad2deg(x(4,i)),'.r','Markersize',5);</p><p>and this:</p><p>plot(t(i),x(4,i)*180/pi,'.r','Markersize',5);</p><p>But the degrees on the graph scale up to larger than what they are supposed to scale up to . That is, they are not directly converting to degrees but to higher values when I do this. Can you please tell me what the issue is? Thank you so much.</p>Mari Yhttp://nl.mathworks.com/matlabcentral/profile/authors/7341282-mari-ytag:nl.mathworks.com,2005:Question/3156082016-12-06T09:25:52Z2016-12-09T03:55:06ZGetting the error: Undefined function 'network' for input arguments of type 'double' while generating neural network using newgrnn<p>Line of code is :
nn_t = newgrnn(ip,op,0.03);</p><p>Tried:
which newgrnn
C:\Program Files\MATLAB\R2016b\toolbox\nnet\nnet\nnnetwork\newgrnn.m
>> which network
C:\Program Files\MATLAB\R2016b\toolbox\nnet\nnet\@network\network.m % network constructor, Has no license available</p>Anjana Krishnanhttp://nl.mathworks.com/matlabcentral/profile/authors/9234736-anjana-krishnantag:nl.mathworks.com,2005:Question/3158742016-12-07T20:28:41Z2016-12-09T03:38:10Zmy problem is how to detect two hands and tracking using matlab2016 but theri is a problem in image acquisition <p>if someone can help me with code can resolve this or
help me in this warning i can't understand it:
Warning: Image is too big to fit on screen; displaying at 67%
> In images.internal.initSize (line 71)
In imshow (line 309)</p>intissar khalifahttp://nl.mathworks.com/matlabcentral/profile/authors/9287101-intissar-khalifatag:nl.mathworks.com,2005:Question/3161172016-12-09T02:15:35Z2016-12-09T03:29:16Zhow to fill the vacancy in a binary image<p>hi
there is a binary image
how can I fill the vacancy(blue) in the yellow region?</p><img src = "/matlabcentral/answers/uploaded_files/65092/untitled.jpg">Meggie Hwanghttp://nl.mathworks.com/matlabcentral/profile/authors/7520415-meggie-hwangtag:nl.mathworks.com,2005:Question/3158272016-12-07T15:00:19Z2016-12-09T03:28:22ZHow Lexicographical sorting is done for image?<p>How Lexicographical sorting is done for image??plz someone explain this.Thanks in advance :)</p>Kanwal Kaurhttp://nl.mathworks.com/matlabcentral/profile/authors/9212294-kanwal-kaurtag:nl.mathworks.com,2005:Question/3161242016-12-09T03:27:55Z2016-12-09T03:28:26ZPlotting - Add label at the end of the x axis<p>Hi everyone,</p><p>I am developing a graph like the figure below. How can I make a label at the end of the x-axis like the red label below? I have tried using</p><pre class="language-matlab">set(xLabel,'Position',get(xLabel,'Position') - [x y z]);
</pre><p>but then the label became invisible since it went outside the graph.</p><p>Thanks</p><img src = "/matlabcentral/answers/uploaded_files/65094/untitled.jpg">Phu Laihttp://nl.mathworks.com/matlabcentral/profile/authors/8428188-phu-laitag:nl.mathworks.com,2005:Question/3159822016-12-08T11:55:47Z2016-12-09T03:26:45Zhow to save the biggest region and discard other small region in a binary image.<p>hi
there is a binary image.how to keep the biggest region and discard other small regions?</p><img src = "/matlabcentral/answers/uploaded_files/65028/untitled.jpg">Meggie Hwanghttp://nl.mathworks.com/matlabcentral/profile/authors/7520415-meggie-hwangtag:nl.mathworks.com,2005:Question/3161232016-12-09T03:19:11Z2016-12-09T04:34:47ZUnder matlab discrete event system, how do i specify multiple storages connecting to one output port<p>For example:</p><pre> function [storageSpecs, I,O] = getEntityStorageImpl(obj)
storageSpecs = [...
obj.queuePriority('student', 25, 'age', 'ascending'), ...
obj.queueFIFO('student', 10)];
I = 2;</pre><p>How do I specify that the output port is connected to both storage</p>Bouquihttp://nl.mathworks.com/matlabcentral/profile/authors/5001057-bouquitag:nl.mathworks.com,2005:Question/3161202016-12-09T03:01:06Z2016-12-09T03:17:19ZWhat is mean about "in numeric Matlab format"?<p>i need to know those numbers is getted</p>Wei Zhanghttp://nl.mathworks.com/matlabcentral/profile/authors/9342095-wei-zhangtag:nl.mathworks.com,2005:Question/3161222016-12-09T03:14:18Z2016-12-09T03:14:18ZMatlab script를 이용하여 Stateflow subchart를 PNG 형식으로 저장하는 방법 문의<p>Matlab script를 이용하여 Stateflow subchart를 PNG 형식으로 저장하는 방법을 알고 싶습니다.</p>JungHoon Jihttp://nl.mathworks.com/matlabcentral/profile/authors/2925670-junghoon-jitag:nl.mathworks.com,2005:Question/3161212016-12-09T03:03:43Z2016-12-09T03:09:02ZHow to import multiple .m files<p>Is there a simple loop or so to call multiple files and extract the sub structures from it where all .m files have the same substructure?</p>liu Jameshttp://nl.mathworks.com/matlabcentral/profile/authors/8449125-liu-jamestag:nl.mathworks.com,2005:Question/3161192016-12-09T02:45:58Z2016-12-09T03:01:42ZFigure style in Matlab<p>Hello everyone,</p><p>I was wondering if it is possible to obtain a figure like the one that I'm showing in Matlab, considering the axes appearence, linetype, dashing type, font, etc.</p><p>I know the basic commands to create a plot with these kind of elements, but I'm not able to obtain something that looks really like this.</p><p>Do you think this is possible?</p><p>Thank you in advance for your help,
Rob</p><img src = "/matlabcentral/answers/uploaded_files/65093/Screen%20Shot%202016-12-09%20at%2015.31.30.png">robhttp://nl.mathworks.com/matlabcentral/profile/authors/4843942-robtag:nl.mathworks.com,2005:Question/3161152016-12-09T01:55:44Z2016-12-09T02:55:01ZCant detect C compiler<p>I have some s function files in C that needs to be converted to MEX.
I installed a c compiler 'MinGW-w64' but my matlab isnt yet detecting it.</p><p>this is what it gives when i type mex 'No supported compiler or SDK was found. For options, visit <a href = "http://www.mathworks.com/support/compilers/R2015a/win64.html">http://www.mathworks.com/support/compilers/R2015a/win64.html</a> .'
get my compiler gives me a blank array.</p><pre class="language-matlab">0x1 CompilerConfiguration array with properties:
</pre><pre> Name
Manufacturer
Language
Version
Location
ShortName
Priority
Details
LinkerName
LinkerVersion
MexOpt</pre><p>I am confused now. What could be a reason for this.</p>Eugenia Balanhttp://nl.mathworks.com/matlabcentral/profile/authors/8582994-eugenia-balantag:nl.mathworks.com,2005:Question/3161162016-12-09T02:03:54Z2016-12-09T02:45:19Zhow to make exe in matlab R2014a ?<p>how to make exe in matlab R2014a ?</p>Ali Ramadhanhttp://nl.mathworks.com/matlabcentral/profile/authors/8790800-ali-ramadhantag:nl.mathworks.com,2005:Question/3161182016-12-09T02:27:30Z2016-12-09T04:43:30ZAnimation of the Lorenz Attractor<p>Hi everybody,</p><p>I'm supposed to modify this code so there's a single dot tracing the plot. I think I'm pretty close I just can't completely get it.</p><p><a href = "https://www.youtube.com/watch?v=0WhkP-VyccY">https://www.youtube.com/watch?v=0WhkP-VyccY</a></p><pre class="language-matlab">function loren3
clear;clf
global A B R
A = 10;
B = 8/3;
R = 28;
u0 = 100*(rand(3,1) - 0.5);
[t,u] = ode45(@lor2,[0,100],u0);
N = find(t>10); v = u(N,:);
x = v(:,1);
y = v(:,2);
plot(x,y);
view(90,90)
M(1)=getframe;
dt=1/100;
for j = 2:1000
t(j)=t(j-1)+dt;
</pre><pre> plot(x*t(j),y*t(j),'o','MarkerFaceColor','b','MarkerSize',8)</pre><pre> M(j)=getframe;
if y<=0, break, end
end
pause
movie(M,1)</pre><pre class="language-matlab">function uprime = lor2(t,u)
</pre><pre class="language-matlab">global A B R
uprime = zeros(3,1);
uprime(1) = -A*u(1) + A*u(2);
uprime(2) = R*u(1) - u(2) - u(1)*u(3);
uprime(3) = -B*u(3) + u(1)*u(2);
</pre>Westin Messerhttp://nl.mathworks.com/matlabcentral/profile/authors/8657825-westin-messertag:nl.mathworks.com,2005:Question/3161132016-12-09T01:43:09Z2016-12-09T02:40:37ZAlgorithm Matlab uses for [V,D] = eigs(A,k);<p>There appear to be a number of ways to compute the top k eigenpairs associated to the matrix A. Does anyone know the one that Matlab uses (via the command eigs(A,k)).
Thanks!</p>David Koslickihttp://nl.mathworks.com/matlabcentral/profile/authors/7519547-david-koslickitag:nl.mathworks.com,2005:Question/3159492016-12-08T08:34:06Z2016-12-09T02:35:55ZPlease tell me how to read multiple excel file one by one to act as input variable in my code!<p>I wrote in my code ACTmtx=xlsread('ACTfile_Instance_J301');Please tell me how can I extend it for 480 other such excel files 'ACTfile_InstanceJ302', 'ACTfile_InstanceJ303',....etc. and so on stored in my PC!</p>DHEERAJ JOSHIhttp://nl.mathworks.com/matlabcentral/profile/authors/7419305-dheeraj-joshitag:nl.mathworks.com,2005:Question/3161122016-12-09T01:36:41Z2016-12-09T02:10:37ZMATLAB Trapezium Rule - Input Error<p>Hi there,</p><p>I have written a mathematical code to calculate the trapezium rule for a set function. For my entire program, I have attempted to make it as 'user-friendly' as possible; whereby all variables are set upon running the code. This way, the script does not need to be editted in any way - see my code if you're confused in any way.</p><p>The issue I have is that when I input the actual mathematical 'function' into the program, it keeps being called multiple times, when I only want it to be called once. For example, if the function I needed evaluating was: 2x^2, I would input ' 2*x.^2 ', but would have to do this several times instead of once.</p><p>I think that the number of times the program calls upon this input is related to the number of strips to calculate - try this and see if you think I'm right? Therefore, I believe the loop inside the script keeps calling the mathematical 'function' user input continuously - I don't know how to stop this from happening?</p><p>I am a beginner to MATLAB and whilst it appears that I'm overcomplicating everything, I'm only trying to make everything as 'user-friendly' as possible...</p><p>My script:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.</p><pre> disp('Trapezium Rule Calculator');
disp('Truth and Absolute Values');
disp('-------------------------');
disp(' ');</pre><pre> % F. Variables
a = input('Enter the value of the lower bound:');
b = input('Enter the value of the upper bound:');
n = input('Enter the number of strips required:');
disp(' ');</pre><pre> h = ((b - a)/ (n));</pre><pre> % Summation of First and Last Tra.
sum = 0.5*( f(a) + f(b) );</pre><pre> % Loop for Middle Tra.s
for i = 1 : n-1;
sum = sum + f(a+i*h);
end</pre><pre> % Truth - Integral Calculation
g = @f;
truth = integral(g,a,b);
disp(' ');
disp('Actual Value of Integral:');
disp(truth);</pre><pre> % Final Value of Tra.
Answer = h*sum;
ModAnswer = abs(Answer);</pre><pre> disp('Value of Trapezium Area Calculated:');
disp(ModAnswer);</pre><pre> % Difference (Accuracy)
ModTruth = abs(truth);
diff = abs( ModTruth - ModAnswer);
disp('Difference in Calculation:');
disp(diff);</pre><pre> % Percentage Accuracy
format short
PInaccuracy = ( (diff) / (ModTruth) )*100;
PA = 100 - PInaccuracy;
disp('Percentage Accuracy (%):');
disp(PA);</pre><pre> % Functions Formulae
function y = f(x)
y = input('Enter function for processing:');
end</pre><p>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>></p><p>Please help me on how to solve this issue please?</p><p>Thank you!</p>M Phttp://nl.mathworks.com/matlabcentral/profile/authors/9341787-m-ptag:nl.mathworks.com,2005:Question/2549572015-11-15T20:14:51Z2016-12-09T02:07:00Zproblem using mex -setup<p>Windows 10 and Matlab 2015b</p><pre class="language-matlab">>> mex -setup
Error using mex
No supported compiler or SDK was found. You can install the freely available MinGW-w64 C/C++ compiler; see
Install MinGW-w64 Compiler. For more options, see
http://www.mathworks.com/support/compilers/R2015b/win64.html.
</pre>miguelhttp://nl.mathworks.com/matlabcentral/profile/authors/1834359-migueltag:nl.mathworks.com,2005:Question/3148852016-12-01T09:57:35Z2016-12-09T01:42:55Zfprintf in a for-loop<p>Hi,</p><p>I'm looking for a way to make my code faster. I'm facing the following problem:</p><p>I have a for-loop of 1:length(events). If the event == 1 the event and venue of the event is written to a text file. However, as the length of events is quite large, it takes some time to write the entire text file. I was wondering if there is a way to first store the array first and write it to the text file once the entire for-loop has been processed?</p><p>This is my code:</p><pre class="language-matlab">for f=events
fprintf(fileid, ' Event%03d: ' , f);
counter=1;
for v= venue_name
if event(f)==1
if counter==1
fprintf(fileid, ' X(%04d,%s) ',event(f),venue_name{v});
counter=counter+1;
else
fprintf(fileid, ' + X(%04d,%s) ',event(f),venue_name{v});
end
end
end
end
</pre><p>Can anyone help me with adapting this code such that it just writes the datafile at the end instead of once every iteration?</p>Bashttp://nl.mathworks.com/matlabcentral/profile/authors/2083156-bastag:nl.mathworks.com,2005:Question/3149162016-12-01T13:40:04Z2016-12-09T01:40:35Zcomparing if specific date and time reside in other two cell arrays<pre> *loop entry(increased by 1 mint)* *Start time* *End time*
'01-Oct-2011 11:12:00' '01-Oct-2011 11:13:00' '01-Oct-2011 11:13:50'
'01-Oct-2011 11:13:00' '01-Oct-2011 11:13:05' '01-Oct-2011 11:14:05'
'01-Oct-2011 11:14:00' '01-cot-2011 11:14:00' '01-cot-2011 11:14:30'
'01-Oct-2011 11:15:00' '01-Oct-2011 11:15:00' '01-Oct-2011 11:16:00'</pre><p>I want to check first element in loop column(using loop) and compare it with all elements in start time column and end time column and fetch all those elements which are according to condition (e.g. if (01-Oct-2011 11:12:00 > start time and < stoptime) and assign all fetched elements to new variable.
Kindly help me to write its script. After checking loop must be incremented and next time i.e. 01-Oct-2011 11:13:00 must be checked in all elements and so on.</p>sikihttp://nl.mathworks.com/matlabcentral/profile/authors/9298036-sikitag:nl.mathworks.com,2005:Question/3160892016-12-08T22:07:34Z2016-12-09T01:27:32ZI want to make a vector A=[15 12 9 6 3] using a for loop. How would you go about this?<p>I have</p><pre class="language-matlab">n=3;
for k=15:-3:n
A(k)=k-3
end
A
</pre>James Wolmeringhttp://nl.mathworks.com/matlabcentral/profile/authors/9048840-james-wolmeringtag:nl.mathworks.com,2005:Question/3153632016-12-04T21:05:52Z2016-12-09T01:26:46ZDifferent conversion when using fgetl to read ascii in serial communication<p>I'm trying to read decimal in serial communication by using fgetl() to get ascii string with 'LF' as a terminator.
The ascii results from fgetl are converted to decimal by using unicode2native.
Everything's work perfect, but recently I noticed that when a square ascii char comes up, the conversion using unicode2native always give 26 in decimal.
I've already solved it by fread(), and get 141 in decimal.
But, i dont't want to read it with fread() because it can't use terminator in serial communication.
Is there any possible ways to solve the conversion issue by using unicode2native?
and if I choose to use fread(), is it possible to use terminator?</p><p>here's my code and the result.</p><pre> sensor=fgetl(ref)
sensor=unicode2native(sensor)</pre><img src = "/matlabcentral/answers/uploaded_files/64738/buatForum1.PNG"><p>This is the result by using fgetl(), the highlighted decimal is the conversion results.</p><img src = "/matlabcentral/answers/uploaded_files/64739/faeaea.PNG"><p>This is the result when using fread() to read decimal, the highlighted decimal is the true decimal.
Thankyou.</p>yusuf gautamahttp://nl.mathworks.com/matlabcentral/profile/authors/6722894-yusuf-gautamatag:nl.mathworks.com,2005:Question/3154512016-12-05T12:27:43Z2016-12-09T00:55:20ZGradient command producing multiple functions<p>Hello,
when I use the gradient command I am given multiple functions as the answer. I assume these are the gradient at each 'root'. Is it necessary to substitute X at a specific position to generate the gradient at the position? Furthermore, will quiver generate the slope field?</p><p>G.</p>Gavin Seddonhttp://nl.mathworks.com/matlabcentral/profile/authors/6295967-gavin-seddontag:nl.mathworks.com,2005:Question/3161072016-12-09T00:09:40Z2016-12-09T00:53:19ZSketch the region R of a lamina which is bounded by the curve y=sqrt*(1-x^2) in the first quadrant.<p>y=sqrt*(1-x^2)
figure</p>senseihttp://nl.mathworks.com/matlabcentral/profile/authors/8206272-senseitag:nl.mathworks.com,2005:Question/3161102016-12-09T00:23:06Z2016-12-09T00:49:05Zhow to make 10 by 10 matrix into 1 by 100?<p>for example i am extracting LBP of 10 images of size 100 by 100. LBP function returns feature vector size 100 by 100 .
to store each fv of each image class consuming 100 rows and 100 columns,</p><p>i want to store each fv belonging to their respective class in one long row forming 100*100= 10,000 rows for each image class.</p><p>similarly i obtain fv 10 by 10,000 for 10 images.</p><p>how can i do that?</p>maidahttp://nl.mathworks.com/matlabcentral/profile/authors/3913872-maidatag:nl.mathworks.com,2005:Question/3156792016-12-06T15:47:10Z2016-12-09T00:48:48ZError Compilng C++ MEX File <p>Hello,
I'm trying to develop a new MEX file and can only compile the file one time before an error appears. I can successfully compile the file from the MATLAB command prompt one time upon launch of MATLAB. Subsequent attempts to compile the file produce an error message</p><pre class="language-matlab">'myfile.mexa64' is locked by the MexLock API
</pre><p>The only solution I've found so far is to restart MATLAB. Any suggestions on how proceed? Or what is causing the error upon compilation? Everything I've read about locking Mex files refers to runtime functions, not compilation.</p><p>Thanks
Keith</p>Keith Sullivanhttp://nl.mathworks.com/matlabcentral/profile/authors/9300623-keith-sullivantag:nl.mathworks.com,2005:Question/3156702016-12-06T15:05:24Z2016-12-09T00:46:47ZConvert 24-bit ADC serial read data from 3-byte format to signed integer (int32)<p>I am receiving EEG data from a 24 bit ADC over serial. The ADC data is transmitting in 3 bytes from MSB to LSB.
The full packet is 21 bytes:</p><ul><li>The first byte is the start byte - 0xFF (255 in decimal)</li><li>Then packet number byte.</li><li>Then the next 3 bytes are the 24 bit ADC value broken into MSB LSB2 LSB1</li></ul><p>I can parse the data fine, but re-constructing a 2's complement signed int32 number is causing issues.
The values I am getting out certainly don't reflect what the ADC should be giving out.</p><p>Below are the lines to read and parse the 504 samples (which gives me 24 ADC values (504samples/21bytes = 24 values)).
I have tried uint8 instead of uchar with similar results (when I try int8 I get a invalid specified precision error).</p><pre class="language-matlab">comEEGSMT = serial(com,'BaudRate',3000000);
fopen(comEEGSMT);
rawData(1:504) = fread(comEEGSMT, 504, 'uchar');
fclose(comEEGSMT);
</pre><pre class="language-matlab">startPackets = find(rawData == 255);
bytes = rawData([startpackets+2 startpackets+3 startpackets+4]);
</pre><p>I have tried the following method to reconstruct the value:</p><pre class="language-matlab">ADC_value = bytes(:,1)*256^2 + bytes(:,2)*256 + bytes(:,3);
</pre><p>and the following line is the formula to convert the above number to volts:</p><pre class="language-matlab">ADC_value_volts = ADC_value*(5/3)*(1/(2^32));
</pre><p>The values are in the range of 4000 - 8000 microvolts with large jumps in value.
The values SHOULD be in the range of 200 - 600 microvolts with small changes.</p><p>I have found other questions relating to similar issues, but have had no success trying the proposed solutions such as in the link below: <a href = "https://uk.mathworks.com/matlabcentral/answers/137965-concatenate-3-bytes-array-of-real-time-serial-data-into-single-precision">https://uk.mathworks.com/matlabcentral/answers/137965-concatenate-3-bytes-array-of-real-time-serial-data-into-single-precision</a></p><p>Any help would be very much appreciated as I've been stuck on this for quite long.</p><p>Thanks
Mark</p>Mark O'Sullivanhttp://nl.mathworks.com/matlabcentral/profile/authors/7427561-mark-o-sullivantag:nl.mathworks.com,2005:Question/3159802016-12-08T11:37:42Z2016-12-09T00:44:26ZImproved Eulers method help<p>Hello,</p><p>I am beginner at matlab and i want to do myself eulers methods but it's stopped at this one. Cause i want data in a row.
In first Eulers method results are correct and everything shows like it should. Can somebody correct me cause i cannot find solution to it?</p><p>First Eulers method program is this:</p><p>h=0.1;
x=0:h:0.5;
y=1;
n=5;
for i=1:n</p><pre> f =(x(i)).^3-(5*(x(i)).^2)+7;
y(i+1)=y(i)+h*f
end
disp(y(i))</pre><p>And this is where i can't get all data in row and correct the first result.</p><p>h=0.1;</p><p>x=0:h:0.5;</p><p>y=1;</p><p>n=1;</p><p>for i=0:1:n</p><pre> for i=0:1:n</pre><pre> j=((i+(i+1))/2);</pre><pre> end</pre><pre> f =(x).^3-(5*(x).^2)+7;</pre><pre> y=y+(h*f);</pre><p>end</p><p>disp(y(i))</p><p>It shows me just the result of y(n)..</p><p>Thank you for help in advance.</p>androSLOhttp://nl.mathworks.com/matlabcentral/profile/authors/4143235-androslotag:nl.mathworks.com,2005:Question/3160972016-12-08T22:51:37Z2016-12-09T00:41:35ZWhat is this block?<img src = "/matlabcentral/answers/uploaded_files/65088/block.jpg">Jfp45http://nl.mathworks.com/matlabcentral/profile/authors/7947163-jfp45