http://mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-10-23T15:49:08Ztag:mathworks.com,2005:Question/1595902014-10-22T00:22:59Z2014-10-23T15:49:08ZUsing parfor instead of for<p>So I'm trying to look at the difference between CPU and GPU program runtimes using a parallel computational scheme. My simple file is attached, but whenever I use parfor with the most computational-heavy area, the runtime is significantly increased (1.8s to 477s). How else can I help speed up the code by implementing parallelization? Is my code too simple to see a performance increase?</p><p>Thanks!</p>Jeremy/matlabcentral/answers/contributors/5009663-jeremytag:mathworks.com,2005:Question/1598442014-10-23T15:40:11Z2014-10-23T15:48:16ZNot enough input arguments?<p>I'm trying to create a function which accepts an input of four values (E, L, a, and R) or an array for a and R values, and returns two outputs of Energy and E for the following equation:</p><p>Energy = (pi*E*L*a^3)/(12*R)</p><p>Here's my code:
function [Energy,E] = Efunc(E,L,a,R)
Energy = (pi*E*L*a^3)/12*R;
end</p><p>This returns the error 'not enough input arguments.' How do I correct this?</p>n/matlabcentral/answers/contributors/5811072-ntag:mathworks.com,2005:Question/1598362014-10-23T15:15:18Z2014-10-23T15:46:13ZHow to find multliple values in larger arrays where the value two above it is a negative<p>I work with larger arrays (100x100) and am trying to develop a script which finds values where the value 2 above it is negative. For example, in the following array:</p><pre class="language-matlab">10 10 10 10 10 10
10 10 -3 10 10 10
10 10 10 10 10 -6
10 10 20 10 10 10
10 10 10 10 10 25
</pre><p>The values I would like to find would be the '20' and '25'.</p><p>Thing I am trying to achieve from the script:</p><ul><li>something which identifies these values in the array (value 2 above it is negative)</li><li>a script which displays the location of where these minima are in the command window</li></ul><p>I suppose it could be done by using if statements, but I'm not sure.</p><p>Thanks for any help :)</p>Oliver/matlabcentral/answers/contributors/5671757-olivertag:mathworks.com,2005:Question/1598292014-10-23T14:20:31Z2014-10-23T15:44:32ZHow to Compare different signals<p>Hello,</p><p>I have some noise measurements and 4 different models that can generate a similar noises using estimated parameters from the real measurements. To compare the estimated noises I calculated the PDF, the CCDF and the PSD.</p><p>To compare the results I used the Kull-Back Leibler divergence of the PDF, the MSE of the CCDF and the RMSE and the corr2 matlab function for the PSD.</p><pre> I am not sure if I did the right thing. </pre><p>Can you please tell me if what I did is correct and do you know any other way or function to make such comparison?</p><p>Thanks.</p>Ismail/matlabcentral/answers/contributors/5242087-ismailtag:mathworks.com,2005:Question/1598452014-10-23T15:42:00Z2014-10-23T15:42:45ZMatrix is close to singular or badly scaled, system identification, control, least mean square method<p>I am trying to estimate a system transfer function from the bode plot using least mean square method, and in my final stage of calculation,</p><p>I have</p><p>V0=89, V2=4.87*10^10, V4= 1.26*10^20</p><p>S0= -6.5*10^3, S2= -2.56*10^10, S4= 2.33*10^20, S6= 6.62*10^29, S8= 1.61*10^39, S10= 2.96*10^48,</p><p>T1= -3.38*10^6, T3=2.53*10^15, T5=-4.09*10^24, T7=-3.85*10^34, T9= -2.02*10^44, T11=9.51*10^53,</p><p>U2= 1.72*10^13, U4= 1.14*10^22, U6= 2.62*10^31, U8= 7.14*10^40.</p><p>Then a matrix M which is</p><p>M = [V0 0 -V2 T1 S2 -T3 -S4 T5 S6;
0 V2 0 -S2 T3 S4 -T5 -S6 T7;
V2 0 -V4 T3 S4 -T5 -S6 T7 S8;
T1 -S2 -T3 -S4 T5 S6 -T7 -S8 T9;
S2 T3 -S4 T5 S6 -T7 -S8 T9 S10;
T3 -S4 -T5 -S6 T7 S8 -T9 -S10 T11;
S4 T5 -S6 U2 0 -U4 0 U6 0;
T5 -S6 -T7 0 U4 0 -U6 0 U8;
S6 T7 -S8 U4 0 -U6 0 U8 0]</p><p>and S= [S0; T1; S2; 0; U2; 0; U4; 0; U6]</p><p>My aim is to find G such that</p><p>M*G = S,</p><p>so I used the command G= M\S;</p><p>and I got a warning which says matrix is close to singular or badly scaled.</p><p>The G matrix I obtained is</p><p>G = [109.5618; 0.0004; 0.0000; -0.0115; 0.0000; -0.0000; 0.0000; -0.0000; 0.0000]</p><p>I am pretty sure the matrix that is close to singular is M. But, I really don't know how to
overcome this warning/problem. When I read up online, most of the explanation were beyond my comprehension.</p><p>Can someone please help me with an easy-to-follow explanation since it is my final year project? and this is just the beginning :-(</p><p>Thanks a lot. I will appreciate any help.</p>Ye/matlabcentral/answers/contributors/4805997-yetag:mathworks.com,2005:Question/1596042014-10-22T04:22:14Z2014-10-23T15:38:24ZCan anyone tell me how to implement these timevarying state space equations in matlab<img src = "/matlabcentral/answers/uploaded_files/19822/Time%20Varying%20Matrices.png">Muhammad/matlabcentral/answers/contributors/5789892-muhammadtag:mathworks.com,2005:Question/1598402014-10-23T15:28:50Z2014-10-23T15:35:58ZImporting from Excel dropping first column<p>Hi everyone,</p><p>I have some code that imports time series data from Excel into MATLAB on my Mac laptop using xlsread. When I send the code to my advisor and he runs it on his PC, he runs into significant problems because his MATLAB seems to skip the date column, so the first column of the imported document is the second column of the Excel file. It occurs to me that this must be a compatibility issue, but I cannot find a quick fix anywhere. Thoughts?</p><p>Thanks in advance.</p>Tristan/matlabcentral/answers/contributors/2710664-tristantag:mathworks.com,2005:Question/1598432014-10-23T15:34:29Z2014-10-23T15:34:29ZChange gain while running the simulation<p>Hi everyone,</p><p>I would like to perform some calculations during the simulation in a Matlab Function with Simulink.
It will be neccessary to update the gain with a matrix, calculated in this Matlab Function.
This way I want to create an adaptive control.</p><p>Is it possible to update the gain from a function inside the model? I haven't found a solution yet. :(</p>Antonio/matlabcentral/answers/contributors/5067491-antoniotag:mathworks.com,2005:Question/1597412014-10-22T22:20:11Z2014-10-23T15:34:15Ztimer not always running<p>I have an event listener callback. In that callback I run the following code:</p><pre> disp('I ran')
t = obj.timer
stop(t);
set(t,'TimerFcn',@(~,~)obj.resize2(h,event_data,axes_I,count,new_xlim,new_position));
start(t)</pre><p>In resize2():</p><pre> disp('I ran too!')</pre><p>Previously I've done:
t = timer;
t.StartDelay = TIMER_START_DELAY;
obj.timer = t;</p><p>I'm seeing code that indicates that the callback ran, but not the resize2() function. I'm seeing something like:</p><pre> I ran
I ran
I ran
I ran
I ran too
I ran
I ran
I ran too
I ran
I ran</pre><p>The way the callback code is setup, I want there always to be at least one call to resize2, following any calls to the callback. Any thoughts on why I am not seeing this?</p><p>Thanks,
Jim</p>Jim Hokanson/matlabcentral/answers/contributors/937359-jim-hokansontag:mathworks.com,2005:Question/1598422014-10-23T15:30:51Z2014-10-23T15:30:51ZTimer FixedRate - no longer fixed rate after a few days<p>I am trying to log the pressure of a vacuum chamber over long durations. I wrote a script that uses GUIDE, timer, and the serial interface to log the pressure at 100 Hz.</p><p>In GUIDE, I create the following timer:</p><p>handles.t = timer('ExecutionMode','fixedRate','Period',0.1,'TimerFcn',{'updatePlot_fcn', hObject});</p><p>In updatePlot_fcn, I query the serial interface for the pressure data, format the data, plot the data to screen, and place it in a log file.</p><p>I found that in the first 24 hours, all my data are recorded (i.e. 10 data points every second). By the second day, I am only logging 7 or 8 data points every second. By the third day, I log on average 2 or 3 data points every second.</p><p>I tried the script on several different computer (with > 16GB memory), they all exhibit this problem. I don't know if it is a Matlab memory leak issue (Matlab does not draw additional memory according to task manager), a timer issue, or something wrong that I am doing with the code.</p>Shawn/matlabcentral/answers/contributors/2636233-shawntag:mathworks.com,2005:Question/1598412014-10-23T15:30:36Z2014-10-23T15:30:36ZHow to recall previous commands... and ADD them to what you've already typed.<p>I know that the up arrow allows you to recall previous commands you've used. It replaces the contents of the current command line with those previous commands.</p><p>I also know that you can also get partial matches by typing and then using the up arrow. For example, if you used the command "plot(x,y)" five commands ago, you can type "plot" and hit the up arrow, and it will cycle through previous commands that start with "plot".</p><p>What I want to do is ADD previous commands to what I've already typed in the command line.
For example, my previous command is "A*B".
Now I want to plot that. If I type "plot(" and hit the up arrow, the "plot(" is REPLACED with "A*B". I want to type "plot(" and hit some key so that I get "plot(A*B".</p><p>I feel like I've seen people do this before, but I can't seem to figure out how.</p><p>PS: I know A*B is easy to type, but this often happens with long expressions that I don't want to retype. I also know that I could hit the up arrow, then add the "plot(" to the beginning, but that's also a pain.</p>Travis/matlabcentral/answers/contributors/5183852-travistag:mathworks.com,2005:Question/1598382014-10-23T15:21:28Z2014-10-23T15:30:21ZHow to eliminate same strings in a cell-array?<p>Thi is my cell-array:</p><p>h={'a','b','c','a','d'};</p><p>How to eliminate one of two equal strings like 'a' in the example and get a result like this:</p><p>v={'a','b','c','d'};</p><p>Thanks in advance for your help!</p>andrea/matlabcentral/answers/contributors/5636424-andreatag:mathworks.com,2005:Question/1598332014-10-23T14:54:35Z2014-10-23T15:25:48Zplotting a graph after for and if else if <p>i have a project to write a script to give the height a cam pushes up a follower from the angle of the cam and then plot the graph of angle versus height.
The radius of the cam is not uniform.
i have written the code and have gotten y values but cannot plot these on a graph.
any insight into what i am doing wrong?
thanks!</p><pre class="language-matlab">Matlab code
for x=0: pi/20: 2*pi; %set up for loop for values between 0 and 2pi
if (x>=0)&&(x<=pi/2)
y=6*(2*x-0.5*sin(x))/pi
elseif (x>=pi/2)&&(x<=2*pi/3)
y=6;
elseif (x>=2*pi/3)&&(x<=4*pi/3)
y=6-3*(1-0.5*cos(3*(x-2*pi/3)))
elseif (x>=4*pi/3)&&(x<=3*pi/2)
y=3
elseif(x>=3*pi/2)&&(x<=7*pi/4)
y=3-1.5*((x-3*pi/2)/(pi/4))^2
else (x>=7*pi/4)&&(x<=2*pi)
y=0.75-0.75*(1-(x-7*pi/4)/(pi/4))^2
end
end
plot(x,y)
</pre>mike lynch/matlabcentral/answers/contributors/5796773-mike-lynchtag:mathworks.com,2005:Question/1597212014-10-22T18:42:32Z2014-10-23T15:24:05ZSo apparently my textbook is out of date<p>I've been working out of DeVries' text on mathematical modeling for biological systems, and am working on the chapter that actually teaches you how to do all of this in Matlab. One of the examples I'm working through concerns the SIR model, and asks you to use the dsolve function to solve an ODE symbolically and for non-explicit solution, as such:</p><p>I = dsolve('DI = -1 + a/(b*S)','S')</p><p>According to the textbook, I should get a nice solved equation out of this (though it doesn't say what it should look like). However, when I actually type it into the terminal, I get</p><p>Warning, it is required that the numerator of the given ODE depends on the highest derivative. Returning NULL.</p><p>Warning, it is required that the numerator of the given ODE depends on the highest derivative. Returning NULL.</p><p>Warning, cannot find an explicit solution</p><p>{�Error using maplemex
Error, (in MTM:-dsolve) invalid input: indices received E, which is not valid
for its 1st argument, t
Error in dsolve (line 13)
r = sym(maplemex(0,'MTM:-dsolve',varargin{:},'returnlist=true'));
Error in matlab2211324625 (line 4)
I = dsolve('DI = -1 + a/(b*S)','S');}</p><p>I'm assuming (as is my professor) that somewhere along the line, Matlab updated their formatting, and now the example equation is set up correctly. Can anyone give me any pointers on how it's <i>supposed</i> to look?</p><p>Thanks!</p>Tessa/matlabcentral/answers/contributors/5806979-tessatag:mathworks.com,2005:Question/1598392014-10-23T15:23:31Z2014-10-23T15:23:31ZShifting problem in output results when using affine tformarray interpolation with DICOM images <p>I have two 3D DICOM images: PT (2x2x2mm voxel size) and CT (1x1x2mm voxel size), and I want to resample the first one (lower resolution) to the second one (higher resoltion) by using the function tformarray. I first calculate the matrices which characterize both images: T_CT and T_PT, which are 4x4 matrices where the first three rows correspond to the voxel size on each axis (img_XX.dspa(i) for i=1 --> x, i=2 --> y, and i=3 --> z) and the following three rows correspond to the image corner in DICOM coordinates (CENTER of the corner voxel, img_XX.dpcj(i) for each axis j=x,y,z). Then I used them to calculate the matrix of the transformation T from T_PT/T_CT in maketform.</p><pre class="language-matlab">T_CT = eye(4);
T_CT(1,1) = img_CT.dspa(1);
T_CT(2,2) = img_CT.dspa(2);
T_CT(3,3) = -img_CT.dspa(3);
T_CT(4,1) = img_CT.dpcx(1);
T_CT(4,2) = img_CT.dpcy(1);
T_CT(4,3) = img_CT.dpcz(1);
</pre><pre class="language-matlab">T_PT = eye(4);
T_PT(1,1) = img_PT.dspa(1);
T_PT(2,2) = img_PT.dspa(2);
T_PT(3,3) = -img_PT.dspa(3);
T_PT(4,1) = img_PT.dpcx(1);
T_PT(4,2) = img_PT.dpcy(1);
T_PT(4,3) = img_PT.dpcz(1);
</pre><pre class="language-matlab">A = PT;
T = maketform('affine',T_PT/T_CT); %transformation matrix
R = makeresampler('linear','fill');
TDA = [1,2,3];
TDB = [1,2,3];
TSB = [img_CT.ddim(1),img_CT.ddim(2),img_CT.ddim(3)]; % dimensions of CT image
TMB = [];
F = 0; % outside of target
B = tformarray(A,T,R,TDA,TDB,TSB,TMB,F); % resampled PT
clear PT; clear A;
PTonCT = B; clear B;
</pre><p>By doing this I get a perfect interpolation of the PT image to the higher resolution. However, it is slightly shifted in the three directions. At a first glance, the shift seems to be between 1 and 1/2 voxel. I tried by shifting the DICOM corner by the voxel lenght in each direction (SEE the two new matrices T_CT and T_PT below) and I got much better results, which makes me think about a problem of indexation of something like that. I mean, matlab considers starting at voxel (1,1,1) instead of (0,0,0) for example. However, I think the shift is still not totally compensated. Any idea of where this problem is coming from? Am I missunderstanding the input data and I must introduce the corner of the corner voxel instead of the center like in DICOM convention or either it is really a problem of first index? Where can I have more information about what this function does and the format of the input data? I already looked at mathworks but it is not very clear...</p><p>Thanks in advance</p><pre class="language-matlab">T_CT = eye(4);
T_CT(1,1) = img_CT.dspa(1);
T_CT(2,2) = img_CT.dspa(2);
T_CT(3,3) = -img_CT.dspa(3);
T_CT(4,1) = -img_CT.dspa(1) + img_CT.dpcx(1);
T_CT(4,2) = -img_CT.dspa(2) + img_CT.dpcy(1);
T_CT(4,3) = -img_CT.dspa(3) + img_CT.dpcz(1);
</pre><pre class="language-matlab">T_PT = eye(4);
T_PT(1,1) = img_PT.dspa(1);
T_PT(2,2) = img_PT.dspa(2);
T_PT(3,3) = -img_PT.dspa(3);
T_PT(4,1) = -img_PT.dspa(1) + img_PT.dpcx(1);
T_PT(4,2) = -img_PT.dspa(2) + img_PT.dpcy(1);
T_PT(4,3) = -img_PT.dspa(3) + img_PT.dpcz(1);
</pre>Ana/matlabcentral/answers/contributors/3952877-anatag:mathworks.com,2005:Question/1598152014-10-23T13:22:53Z2014-10-23T15:14:32Zhow to vectorize the following code?<p>Could anyone explain the steps?</p><pre class="language-matlab">DelayStep = 60;%in seconds
MaxStep = 86400;
for j=dStart:dEnd
currDay = datevec(j);
for k=0:DelayStep:MaxStep
hms = [0 0 0 fix(mod(k, [0, 3600, 60]) ./ [3600, 60, 1])];
UTCTimetoCalculate = datestr(hms+currDay);
</pre><pre> end
end</pre>UCL student/matlabcentral/answers/contributors/4746756-ucl-studenttag:mathworks.com,2005:Question/1596452014-10-22T11:33:18Z2014-10-23T15:14:00ZThe variable g in a parfor cannot be classified..<p>Can anyone help me with this?</p><pre> parfor j=1:N
z1r=normrnd(Z1(1),Z1(2)); %Random sample from distribution of Z1
z2r=normrnd(Z2(1),Z2(2)); %Random sample from distribution of Z2
for i=1:size(T,2)
g(i)=Threshold-M(i,1)-(sqrt(lambda1)*V1(i)*z1r)-(sqrt(lambda2)*V2(i)*z2r);
if g(i)>0 %safe
IND(i,j)=0;
else %failure
IND(i,j)=1;
end
end
end</pre>theodor/matlabcentral/answers/contributors/847279-theodortag:mathworks.com,2005:Question/1598352014-10-23T15:12:30Z2014-10-23T15:12:30ZIs it possible to get expression/formula of Neural Network Toolbox?<p>Hi all,</p><p>I have a dependency P(x,y,z), thus, this is 4D function. My goal is to find an analytic expression of P as a function of x,y,z. I used Neural Network Toolbox to analyse my data (train, validated and so on). It seems that it gives very good fit with MSE of 1e-7 and R-square of 0.997. I am wondering if it is possible to get an expression where I could manually plug in x,y,z and get P values.</p><p>Best Regards
Rokas,</p>Rokas Bondzinskas/matlabcentral/answers/contributors/5810235-rokas-bondzinskastag:mathworks.com,2005:Question/1586142014-10-14T18:44:52Z2014-10-23T15:12:00ZHow can I generate code using Simulink PLC Coder for fminsearch function? <p>Hi,
I'm trying to generate code for a MATLAB Function Block where I use the method <i>fminsearch</i> in Simulink, but I get some errors.</p><p>I decided to create a model with just the MATLAB Function Block and a code using <i>fminsearch</i> (as simple as possible) like this:</p><pre class="language-matlab">function y = myfminsearch(u)
%#codegen
y = fminsearch(@myfun,u);
</pre><pre class="language-matlab">function f = myfun(x)
f = (x+5)^2+5;
</pre><p>Even if the method is supposed to work for code generation I get this error:</p><pre> Call to unsupported function 'frexp' detected.</pre><pre class="language-matlab">Function 'eps' (#42.910.941), line 31, column 17
Function 'fminsearch' (#41.14645.14653), line 451, column 25
Function 'fminsearch' (#41.14645.14653), line 451, column 25
Function 'fminsearch' (#41.6622.6656), line 195, column 53
Function 'fminsearch' (#41.6622.6656), line 195, column 53
Function 'MATLAB Function1' (#25.34.54), line 3, column 5
Function 'MATLAB Function1' (#25.34.54), line 3, column 5
Component: stateflow | Category: PLC Coder errorOpen
</pre><pre> Errors occurred during codegenIR Construction failed
Component: simulink | Category: PLC Coder error</pre><p>Can you see what the problem is? I don't really understand the error...
Do you think I can't use <i>fminsearch</i> for code generation?</p><p>Thank you guys!</p>Julian Peña/matlabcentral/answers/contributors/4222086-julian-penatag:mathworks.com,2005:Question/1598322014-10-23T14:33:09Z2014-10-23T15:11:14ZWhy textscan inserts 0 instead of NaN ?<p>Hello,</p><p>I use textscan to import a text file which is a mixture of number and strings. The format is like:</p><p>VGAHFID,VGALFID,SN_hd</p><p>63484,49736,S410060Y_0</p><p>54696,54744,S410060Y_0</p><p>,,S410060Y_0</p><p>53092,54512,S410060Y_0</p><p>53716,54568,S410060Y_0</p><p>53800,54768,S410060Y_0</p><p>The command I used is
a = textscan(fid,'%d%d%q','Headerlines',1,'Delimiter',',','EmptyValue',NaN);</p><p>Here's the result.</p><p>>> a{2}
ans =</p><pre> 49736
54744
0
54512
54568
54768</pre><p>If I changed the NaN to Inf, the missing value will be replaced with 2147483647.</p><p>I guess it must be my "a" format issue. But don't know how to solve it.</p><p>Thanks,
Jane</p>Jane/matlabcentral/answers/contributors/1380287-janetag:mathworks.com,2005:Question/1597112014-10-22T18:08:48Z2014-10-23T15:09:15ZCopy table's certain data into another table with corresponding variable names<p>Let's say I have a table with 10 rows and 10 columns. I'd like to copy 5 cols and 10 rows of the table into another one with their variable names. Is there a way to do that?</p><p>Thank you.</p>Ege/matlabcentral/answers/contributors/5717230-egetag:mathworks.com,2005:Question/1307112014-03-25T04:00:00Z2014-10-23T15:04:35ZWhy am I unable to start MATLAB on my Mac Pro (2013) with two Thunderbolt displays?<p>If I connect two Thunderbolt displays to my new Mac Pro I am not able to run or install MATLAB. Is there any workaround? </p><p>This is the error from Console:</p><pre class="error"> A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000010ef43400, pid=13024, tid=5891
#
# JRE version: 7.0_11-b21
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.6-b04 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [libinstutil.dylib+0x9f400] l_getid_type+0xded</pre>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:mathworks.com,2005:Question/1598342014-10-23T15:03:55Z2014-10-23T15:03:55ZNational Instruments DAQMX function support in matlab<p>Hi,</p><p>I have a national instruments PCI-DIO-32HS digital card and I'm trying to use matlab's data acquisition toolbox. I have Daqmx 9.8 installed, matlab can see the card and communicate with it fine. My issue is that I cannot find any support in Matlab's legacy or session based acquisition that supports what NI calls burst export clock (<http://zone.ni.com/reference/en-XX/help/371893D-01/6536and6537help/programming_burst/)>. This functions exports the clock from the card to a device, the ni function supports arguments for clock polarity used to trigger an event (e.g. off when high). Although matlab has an addclockconnection, there seems to be no support for an of these additional arguments (see link above).</p><p>Am I missing something here?</p>Senaasa/matlabcentral/answers/contributors/4211999-senaasatag:mathworks.com,2005:Question/1598172014-10-23T13:39:27Z2014-10-23T15:02:14Zgriddata for closed surface<p>I have spherical data [theta, phi, R]: <i>R = f(theta, phi)</i></p><p>I need to interpolate this data. I've used griddata function and got a nice result, but with an
issue: it's not interpolated as a closed surface:</p><p>it looks like a rumpled orange (as I wanted), but there is no smooth seam line. So the data near edges are not interpolated as needed.</p><p>Is there any variants of griddata function for closed manifolds?
Or maybe some variants to solve this problem?</p>Evgheny/matlabcentral/answers/contributors/2228981-evghenytag:mathworks.com,2005:Question/1598022014-10-23T11:35:46Z2014-10-23T14:58:07ZSection a 2d matrix and put the sections into a 3d matrix<p>Hi,</p><p>I have a question, if I have a matrix, lets say a 3x12 matrix:</p><pre class="language-matlab">a=
1 1 1
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
2 2 2
3 3 3
3 3 3
3 3 3
3 3 3
</pre><p>is there a method other than for looping to section this matrix and place the elements in a 3d matrix such, that it has a structure of (without changing the position of the 1, 2, 3 elements):</p><pre class="language-matlab">b(:,:,1) =
</pre><pre> 1 1 1
1 1 1
1 1 1
1 1 1</pre><pre class="language-matlab">b(:,:,2) =
</pre><pre> 2 2 2
2 2 2
2 2 2
2 2 2</pre><pre class="language-matlab">b(:,:,3) =
</pre><pre> 3 3 3
3 3 3
3 3 3
3 3 3</pre><p>Is there a method doing this without using for looping?</p>lee/matlabcentral/answers/contributors/5210112-leetag:mathworks.com,2005:Question/1598122014-10-23T12:46:36Z2014-10-23T14:55:44ZSymbolic Math Toolbox - Derive a function with respect to another function<p>Hello,</p><p>i want to verify a calculation I did already on paper. There the following problem occurs:</p><pre class="language-matlab">>> clear all
>> syms t x(t)
>> f=3*x
>> diff(f,x)
Error using sym/diff (line 26)
All arguments, except for the first one, must not be symbolic functions.
</pre><p>I want to derive a funtion woth respect to another function of time. And i even need the derivation of a function with respect to another derivative of a function of time.</p><p>I need this because I want to get the equations of motion of a system by using <a href = "http://en.wikipedia.org/wiki/Lagrangian_mechanics#Derivation_of_Lagrange.27s_equations">Lagrange equations of the second kind</a> .</p><p>Can anybody help me with this problem?
Thanks a lot.
Johannes</p>mistajojo/matlabcentral/answers/contributors/3795967-mistajojotag:mathworks.com,2005:Question/1598222014-10-23T13:58:02Z2014-10-23T14:54:23ZVectorization of a for loop (addition of a vector)<p>Hello MATLAB community,</p><p>I have a question concerning the vectorization of a for loop to speed up my code.
What I have is a vector, let´s say:</p><pre class="language-matlab">a = [1 2 3 4 5 6 7 8 ]
</pre><p>What I want to do is to create a vector, which makes an addition of all values in the vector to the point which I am actually at. In this case it would be:</p><pre class="language-matlab">a_new = [1 3 6 10 15 21 28 36]
</pre><p>It´s no problem to code this with a for loop.</p><pre class="language-matlab">s_neu = zeros (1,length(s),'double');
</pre><pre class="language-matlab">s_neu(1,1) = s(1,1);
</pre><pre class="language-matlab">for i = 2:length(s)
</pre><pre> s_neu(1,i) = s_neu(1,i-1)+s(1,i);</pre><pre class="language-matlab">end
</pre><p>Do anyone of you know, how to code this without the for loop?
Thank you very much!</p>David/matlabcentral/answers/contributors/4226882-davidtag:mathworks.com,2005:Question/1581602014-10-10T14:16:19Z2014-10-23T14:52:12ZLatex Interpreter MATLAB title underscores<p>Hi there,</p><p>I was using this title command as the title of the plot:
title(['File:' filename 'Stim electr: 'num2str(StimElectr(n))])</p><p>The filename contains underscores that are interpreted as subscripts in my MATLAB 2013b. Turning off the LaTEX interpreter locally seems to work only when I do not include the strings 'File:' and 'Stim electr' in my title command.</p><p>In other words, this works fine: title(filename,'interpreter','none') and underscores are kept as they are, but this doesn't: title(['File:' filename, 'interpreter', 'none']).</p><p>How can I keep the underscores for my initial title command?? (back slash etc I cannot use coz I cannot change the filename manually each time)</p><p>Thanx a lot!!
Stelina</p>Stelina/matlabcentral/answers/contributors/3722431-stelinatag:mathworks.com,2005:Question/1590162014-08-01T04:00:00Z2014-10-23T14:49:37ZIs MATLAB compatible with Mac OS X 10.10 (Yosemite)?<p>I want to upgrade my Mac to OS X 10.10 (Yosemite). I want to know if MATLAB and related products are compatible with this OS.</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:mathworks.com,2005:Question/1598012014-10-23T11:21:25Z2014-10-23T14:47:08ZTrying to connect XCode 5 and Matlab 2014a and get an AWT-EventQueue-0 error<img src = "/matlabcentral/answers/uploaded_files/19893/Screen%20Shot%202014-10-23%20at%2012.18.04.png"><p>I get an error message when I try to attach a Matlab process to XCode. Before attaching, I have put the .C code in the new project, checked it's fine (apparently so). I immediately get this error when I start clicking on the Matlab window (i.e to go to a directory I want, or run a script).</p><p>Any advice?</p><p>Regards,</p><p>F</p>Fran/matlabcentral/answers/contributors/3493072-frantag:mathworks.com,2005:Question/1597622014-10-23T02:39:01Z2014-10-23T14:44:47ZHow to create a for loop in function with a step size as input?<p>My current function is:</p><p>.
.</p><img src = "/matlabcentral/answers/uploaded_files/19884/fucntion.jpg"><p>.</p><p>x is supposely to run from 765 to 805 with myself individually keying in the step size</p><p>X Eg. 765 -> 770 -> 775 -> 780 .... (step size: 5)</p><pre> 765 -> 767 -> 769 -> 771 .... (step size:2)
.
.
.
765 -> 765.1 -> 765.2 -> 765.3 (step size:0.1)</pre><p>.</p><p>is repetitive procedure.</p><p>So Im thinking of changing X as the input of step size and 765 to 805 already implemented in the function. But Im foreign to the command of for loop.</p><p>Anyone can help? Will greatly appreciate it!
Thanks!</p>ZONG YI Ng/matlabcentral/answers/contributors/5751907-zong-yi-ngtag:mathworks.com,2005:Question/1596012014-10-22T03:25:38Z2014-10-23T14:43:41ZWhat does the error "No response when requesting system info" mean in the diagnostics and how do I fix it?<p>Hello. My name is Nicholas and I am a seventh grader participating in the BEST robotics competition this year. When attempting to download my program, I received this message in the diagnostics. I think that it is preventing the program from being downloaded. What does it mean and how can it be fixed?</p><p>Thank you</p><img src = "/matlabcentral/answers/uploaded_files/19816/simulink.PNG">Nicholas/matlabcentral/answers/contributors/5786251-nicholastag:mathworks.com,2005:Question/1595592014-10-21T18:09:24Z2014-10-23T14:38:45ZExtract Data from for loop<pre> I am attempting to plot SFC and TSFC vs The PRC values based on each value of Mach. I am trying to find a way to extract all calculated values of SFC and TSFC from the for loop for plotting. Any help would be appreciated</pre><pre> U = Mach*sqrt(gamman*R*Ta);
Toa = Ta.*((1+(((gammad-1)/2).*(Mach^2))));
To2 = Toa;
To2sTa = (1+((etad.*((To2./Ta)-1))));
Po2 = Pa.*((To2sTa).^(gammad/(gammad-1)));</pre><pre> for PRC = 5:5:100
Po3 = PRC.*Po2;
To3 = To2.*(1+((1./etac).*(PRC.^((gammac-1)/gammac))-1));
for To4 = [1500 1600 1700]</pre><pre> Cpb = ((R*gammab)/(gammab-1));
f = ((To3.*((To4./To3)-1))./((QR/Cpb)-To4)); </pre><pre> Po4 = Po3;
To5 = To4-To3+To2;
Po5 = (Po4.*(1-(1./etat)*(1-(To5/To4))).^(gammat/(gammat-1)));</pre><pre> U7 = sqrt((2*etan*R*(gamman/(gamman-1)))*To5*((1-(Pa/Po5)).^(gamman-1/(gamman))));
SFC = ((1+f)*U7-U)/1000; %((kN*s)/(kg))
TSFC = f*SFC; %((kg)/(kN*s))
end</pre><pre> end</pre><pre class="language-matlab">end
</pre>G/matlabcentral/answers/contributors/4000106-gtag:mathworks.com,2005:Question/1598312014-10-23T14:30:04Z2014-10-23T14:30:04ZSimulink Real Time are the benchmark results acceptable?<p>Hi,</p><p>I'm checking the performance of my target computer. I suspect the results are not satisfactory, however I will be thankful for an opinion of an advanced user. Here are the resutls:</p><p>Benchmark results for model: Minimal
Number of blocks in model: 3
Elapsed time for model build (sec): 7.3
Elapsed time for model benchmark (sec): 224.9
Minimal achievable sample time (microsec): 24.5</p><p>Benchmark results for model: F14*1
Number of blocks in model: 61
Elapsed time for model build (sec): 8.5
Elapsed time for model benchmark (sec): 222.8
Minimal achievable sample time (microsec): 25.9</p><p>Benchmark results for model: F14*5
Number of blocks in model: 305
Elapsed time for model build (sec): 10.1
Elapsed time for model benchmark (sec): 269.6
Minimal achievable sample time (microsec): 29.3</p><p>F14*10 FAILS at sample time 0.000028, execution time ~2s. The target computer gets then disconnected and the connection cannot be restored unless I restart the target.
F14*25 fails at sample time 0.000035, execution time ~8s.</p><p>Specs: Target: Intel Core i5, 3.3GHz</p><p>Host: Intel Core i5, 2.53GHz; 64-bit Windows 7, MATLAB R2014a</p><p>RS-232 Connection</p>Marta/matlabcentral/answers/contributors/4695449-martatag:mathworks.com,2005:Question/1598302014-10-23T14:22:27Z2014-10-23T14:26:07Zfminsearch for complex input for curve fitting<p>Dear all,
I would like to fit experimental data with custom equations. I aim for the best fit of the theoretical curve to the experimental data by minimizing the residuals and use fminsearch to find minimal error.</p><p>The attached code works well for the real inputs</p><p>[R, fval] = fminsearch(err, 2.11)% finds the minimum of err But it fails for the</p><p>[R, fval] = fminsearch(err, 2.0-0.064i)</p><p>Help for fminsearch suggests to input split into real, imaginary parts and work to obtain the best fit. I have a little idea of doing this.</p><p>Could somebody help me with this problem? Thanks all.</p>VISWANATH/matlabcentral/answers/contributors/867021-viswanathtag:mathworks.com,2005:Question/1597972014-10-23T10:46:41Z2014-10-23T14:21:49ZError using ode45 in matlab<p>Hi guys</p><p>I have a block and spring system with no damping. I'm given the equation x'' = -k*(x1 - L1)/m + k*(x2-x1-w1-L2)/m. Where k = spring stiffness; x1 = initial position of block; L1 = length of spring; x2 = initial position of the end of block; w1 = width of block; L2 = length of second block.</p><p>I have converted the second order ode into 2 first order odes.</p><p>u1' = x1' = u2</p><p>u2' = -k*(u1 - L1)/m + k*(u3-u1-w1-L2)/m</p><p>This is my function</p><p>function ydot = jipo1(t,y)</p><p>m = 2; % mass of the block</p><p>k = 5; % Spring stiffness</p><p>L1 = 2; % length of unstretched spring</p><p>k2 = 5; % Spring stiffness</p><p>L2 = 2; % length of unstretched spring</p><p>w1 = 5; % length of block</p><p>yd1 = y(2);</p><p>yd2 = -k*(y(1)-L1)/m + k2*(y(3)-y(1))/m</p><p>ydot = [yd1;yd2];</p><p>end</p><p>This is my ode45 script</p><p>clc</p><p>m1 = 2; % mass of the block</p><p>k = 5; % Spring stiffness</p><p>k2 = 5; % Spring stiffness</p><p>wn1 = sqrt(k/m1); % Natural frequency</p><p>t_final = 20; % Calculation time</p><p>L1 = 2; % length of unstretched spring</p><p>L2 = 2; % length of unstretched spring</p><p>w1 = 5; % length of blockk</p><p>x1_0 = 2; % Initial displacement</p><p>x_dot_0 = 0; % initial velocity</p><p>X_0 = [x1_0,x_dot_0]; % form a vector (array) of initial conditions</p><p>[t,y] = ode45(@jipo1,[0,t_final],X_0);</p><p>When I run it Matlab gives me this error.</p><p>Error in ode45 (line 114)</p><p>[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...</p><p>Error in jipo (line 18)</p><p>[t,y] = ode45(@jipo1,[0,t_final],X_0);</p><p>I would really appreciate any help that will help me understand what I'm doing wrong.</p>tyler brecht/matlabcentral/answers/contributors/5574479-tyler-brechttag:mathworks.com,2005:Question/1596462014-10-22T11:34:55Z2014-10-23T14:18:23ZLinux UDP Send block fails to send to broadcast address<p>I have a Simulink model that generates target code to run under Embedded Linux (3.3.0) on a target OMAP-L138 LCDK board. The model periodically uses a Linux UDP Send block to transmit a small packet of data to a host PC. The block parameters are: port 7000, address '10.255.255.255'. When I generate the code a file called linuxUDP.c is created. If I build the code and download to the target and run it I never see the UDP message coming from the board.</p><p>I found that I have to manually edit the linuxUDP.c file to add a 'broadcast' option to the socket, i.e;:</p><p>int BroadcastEnable = 1;</p><p>setsockopt(((TgtSockStructT *) device)->sockfd, SOL_SOCKET,
SO_BROADCAST, &BroadcastEnable , 4);</p><p>Then when I build the modified code and run it everything works fine and the UDP message is transmitted from the target.</p><p>Is this a bug with the generated code from the model or am I doing something wrong with the block that is stopping the broadcast message from being sent? I tried using address '255.255.255.255' but I still had to make the same mods to the linuxUDP.c to get the message to be sent.</p>Mike Bardill/matlabcentral/answers/contributors/841081-mike-bardilltag:mathworks.com,2005:Question/1598282014-10-23T14:16:07Z2014-10-23T14:16:07Zunexpected xlim behavior - where is the documentation/code for how xlim gets updated<p>Is the way that the xlim property of an axes changes documented? I have some code that waits a bit - via a timer - after a series of axes manipulations are done, before finally updating a plot (see pseudocode below). I found however that if I wait to replot after zooming out, the algorithm decides that my data doesn't encompass the wide range that I zoomed out to, and then shrinks the xlim values accordingly.</p><p>In other words, let's say the original data spans from 0 to 100. Then I zoom from 30 to 60. When plotting for xlim = [30 60], I only plot data from 30 to 60. Then I zoom back out to 0 to 100 via a zoom reset (mouse double click). A timer is started in the xlim change callback. If the change is stable, then I'll replot things from 0 to 100. However, if another xlim change occurs, perhaps from quick zooming or panning, then I hold off on rerendering until all the input stops, at which point I use the latest xlim value.</p><p>This is the rough pseudocode:</p><p>xlim_changed_callback:
%Responding to xlim postset listener for axes</p><pre> delete(old_timer)
start(new_timer)</pre><p>timer_callback:</p><pre> updatePlot</pre><p>However, by waiting to plot, the xlim algorithm appears to check the resulting data span (somehow) and determines that the data doesn't encompass the region of 0 to 100, and changes its value again, so that it fits the data (which has yet to be updated). Thus the latest xlim value that I have to work with is close to being back to 30 to 60, even though at one point the value was changed to the proper value of 0 to 100.</p><p>Issue 2: As a workaround I quickly plot a temporary line on every callback that spans the xlim range, so that the algorithm doesn't decide to change the xlim value. When the timer actually executes, I then replot the lines with valid data.</p><p>However, this causes a slight adjustment of the xlim values. In the example above, my xlim value of [0 100] will change to [0.000001 100]. What is causing this? Can I prevent this from happening? My current workaround is to check for this "small" change and to ignore setting the new timer if this occurs.</p><p>Any incite into this whole process or suggestions would be much appreciated.</p><p>Thanks,
Jim</p>Jim Hokanson/matlabcentral/answers/contributors/937359-jim-hokansontag:mathworks.com,2005:Question/1598132014-10-23T13:20:17Z2014-10-23T14:14:25ZFilling data gaps in a periodic timeseries in MATLAB<p>I am looking for a method to fill in data gaps in a time-series that contains periodic data (in this case with a frequency equal to a tidal frequency, so both semi-diurnal and spring/neap frequencies) using MATLAB. The data series also contains noise which I would like to superimpose on top of the artificial data that fills the time gap. The data has a certain trend that I want to preserve. Ideally I would be looking at a method that uses the recorded data on either side of the time gap. The data files are too large to post here. However the sampling rate is 5 mins and there is approximately a week worth of data missing.</p><p><<</p><img src = "/matlabcentral/answers/uploaded_files/19896/Data_gap_zoom.png"><p>>></p><p>Is there anyway of doing this in Matlab?</p><p>Thank you.</p><p>Donald John</p>Donald John/matlabcentral/answers/contributors/3327612-donald-johntag:mathworks.com,2005:Question/1598272014-10-23T14:13:30Z2014-10-23T14:13:30ZI am doing some inegration with respect to (t) to find the Fisher Information but I need to check if my code is working correctely?<p>The code is:</p><p>function RunLogisticOscilFisher</p><p>omega=1;</p><p>k=10;</p><p>N0=1;</p><p>A=1;</p><p>p0=.1;</p><p>t=(0:0.001:10);</p><p>% Finding the numerical solution for the function using ode45 solver</p><p>[t,p]=ode45(@logisticOscilfisher,t,p0,[],N0,k,omega);</p><p>% Plotting the function with time</p><p>figure(1)</p><p>plot(t,p)</p><p>title('The function with Time')</p><p>xlabel('Time')</p><p>ylabel('The function')</p><p>% Defining my variable (p) as a function of (t)</p><pre> P=@(T) interp1(t,p,T); </pre><p>% Finding the integral to get the Fisher Information</p><p>f = @(T) ( ((25.*A.*(1./25).*sin(t).^4.*(10-2.*P(T)).^2)+cos(t).^2 )./(P(T).^2.*(10-P(T)).^2.*(sin(t).^4) ) )</p><p>I1=integral( f, 0,2,'ArrayValued',true)</p><p>I2=integral( f, 0,4,'ArrayValued',true)</p><p>I3=integral( f, 0,6,'ArrayValued',true)</p><p>I4=integral(f,0,8,'ArrayValued',true)</p><p>I5=integral(f,0,10,'ArrayValued',true)</p><p>I=[I1./2 I2./4 I3./6 I4./8 I5./10]</p><p>T=[2 4 6 8 10];</p><p>%Plotting the Fisher Information</p><p>figure(2)</p><p>plot(T,I); % axis([0 10 0.1 0.3])</p><p>title('The fisher Information')</p><p>xlabel('Time')</p><p>ylabel('FI values')</p><pre> 1;</pre><p>% function dpdt = logisticOscilfisher(t,p,N0,k,omega)</p><p>% dpdt = N0*sin(omega*t)*p*(1-p/k);</p><p>% end</p>Avan Al-Saffar/matlabcentral/answers/contributors/5297065-avan-al-saffartag:mathworks.com,2005:Question/1598262014-10-23T14:08:33Z2014-10-23T14:08:33ZMedian Inner Size Compact Boxplot<p>I have used the Compact plotstyle for matlab box plot and turned off the tags for box, outliers, and median outer. Essentially all I want to see is a straight line for the whisker and IQR and a black diamond or other symbol for the median. I have made some example data below with the code I have been using. The problem is that although the medianinner markers show up nicely in the fig window they print out very small in jpeg form. How do I get the medianinner markers to display in jpg like they do in fig???</p><p>Example Code;:
X = [2 4 3 6 4 3 12;3 6 4 2 15 8 5;2 2 3 1 5 19 4]';</p><p>figure</p><p>b = boxplot(X,'plotstyle','compact');
h1 = findobj(gca,'Tag','Outliers');
set(h1(:,:),'Visible','Off');
h2 = findobj(gca,'Tag','Box');
set(h2(:,:),'Visible','Off');
h3 = findobj(gca,'Tag','MedianOuter');
set(h3(:,:),'Visible','Off');
h4 = findobj(gca,'Tag','MedianInner');
set(h4(:,:),'LineWidth',5)</p><p>print boxplot.jpg -djpeg -r300</p><p>I am only interested in how to print this so it looks like the display in the figure window. I have tried increasing the size of the medianinner and this does not work. I have also tried making the medianouter bigger and then turning it off in case it was restricting the medianinner and this did not work either.</p>David/matlabcentral/answers/contributors/5810562-davidtag:mathworks.com,2005:Question/1596652014-10-22T12:55:26Z2014-10-23T14:07:35ZIs it possible to modify the matrices in a genss ?<p>Hello everybody!</p><p>Do you know if it's possible to change one of the matrices componing a genss (not only the tunable parameter) ?</p><p>For example the following system:</p><pre class="language-matlab">a = realp('a', 10); % The tunable parameter
A = [ 0 1; 1 a];
B1 = [1; 0];
B2 = [1 2; 0 1];
C = [1 1];
D = 0;
</pre><pre class="language-matlab">G = ss(A, B1, C, D);
</pre><p>Now I want to change the B matrix (to cope with more inputs for example) but I don't want to create a new genss (maybe I can't access A, C and D matrices, which could be much more complicated).</p><p>My question is: is it possible to change the B1 matrix by the B2 matrix in G ?</p><p>It's seems it's not even possible to access the A, B, C and D matrices of G except for the current value (but A won't be a genmat).</p><p>Does anybody have any idea ?</p><p>Thank you !
Stéphane</p>Stephane/matlabcentral/answers/contributors/1897664-stephanetag:mathworks.com,2005:Question/1598252014-10-23T14:04:43Z2014-10-23T14:04:43Zspeech recognition using svm<p>speech recognition using svm and genetic algorithm</p>imene s/matlabcentral/answers/contributors/5806441-imene-stag:mathworks.com,2005:Question/1598242014-10-23T14:03:43Z2014-10-23T14:03:43Zmex difference between mwPointer and pointer in Fortran90<p>What is the difference between <b>mwPointer</b> and intrinsic <b>pointer</b> in Fortran 90? Can you use mwPointer the way you would use an intrinsic F90 pointer?</p><p>Thanks
Rob</p>Robert/matlabcentral/answers/contributors/3219772-roberttag:mathworks.com,2005:Question/1250212014-04-08T18:50:14Z2014-10-23T14:03:20ZParallel computing corruption problem (Windows)<p>Hello,</p><p>I'm having a problem with parallel computing that is driving me nuts as I feel like I've exhausted all plausible causes. When I first installed matlab, parpool worked and I was able to run a parallel for loop. After that it didn't work and keeps failing with a long chain of errors.</p><p><i>Warning: Failed to remove the following invalid children under the profiles node:
local
> In NamedNodesCollection>NamedNodesCollection.refreshCache at 302
In NamedNodesCollection>NamedNodesCollection.refreshCacheIfRequired at 267
In NamedNodesCollection>NamedNodesCollection.getAllNames at 115
In Settings.Settings>iReplaceBadDefaultProfileWithLocal at 674
In Settings.Settings>Settings.hGetProperty at 148
In Settings.Settings>Settings.buildProperties at 629
In Settings.Settings>Settings.Settings at 324
In argumentsParser>iGetClusterAndNumWorkers at 112
In argumentsParser at 43
In parpool at 91
Warning: Failed to remove the following invalid children under the profiles node:
local
> In NamedNodesCollection>NamedNodesCollection.refreshCache at 302
In NamedNodesCollection>NamedNodesCollection.refreshCacheIfRequired at 267
In NamedNodesCollection>NamedNodesCollection.getAll at 59
In NamedNodesCollection>NamedNodesCollection.getAllNames at 116
In Settings.Settings>iReplaceBadDefaultProfileWithLocal at 674
In Settings.Settings>Settings.hGetProperty at 148
In Settings.Settings>Settings.buildProperties at 629
In Settings.Settings>Settings.Settings at 324
In argumentsParser>iGetClusterAndNumWorkers at 112
In argumentsParser at 43
In parpool at 91
Warning: Failed to remove the following invalid children under the profiles node:
local
> In NamedNodesCollection>NamedNodesCollection.refreshCache at 302
In NamedNodesCollection>NamedNodesCollection.refreshCacheIfRequired at 267
In NamedNodesCollection>NamedNodesCollection.nameExists at 107
In Settings.Settings>iReplaceBadDefaultProfileWithLocal at 695
In Settings.Settings>Settings.hGetProperty at 148
In Settings.Settings>Settings.buildProperties at 629
In Settings.Settings>Settings.Settings at 324
In argumentsParser>iGetClusterAndNumWorkers at 112
In argumentsParser at 43
In parpool at 91
Warning: The local profile cannot be found. Your installation might be corrupt.
Error using parpool (line 99)
The operation must modify one or more Settings files for these levels: factory, user, but you do not have write
permission on these levels: user.</i></p><p>I reinstalled matlab, and then it worked again the first time, but not again. Since then it hasn't worked even after reinstalling. Trying to open the cluster manager fails with error:</p><p><i>com.mathworks.jmi.MatlabException: The operation must modify one or more Settings files for these levels: factory, user, but you do not have write permission on these levels: user.
at com.mathworks.jmi.NativeMatlab.SendMatlabMessage(Native Method)
at com.mathworks.jmi.NativeMatlab.sendMatlabMessage(NativeMatlab.java:265)
at com.mathworks.jmi.MatlabLooper.sendMatlabMessage(MatlabLooper.java:120)
at com.mathworks.jmi.Matlab.mtFeval(Matlab.java:1541)
at com.mathworks.jmi.MatlabWorker.feval(MatlabWorker.java:197)
at com.mathworks.toolbox.distcomp.ui.profile.model.MatlabProfileManager$1.runOnMatlabThread(MatlabProfileManager.java:72)
at com.mathworks.jmi.MatlabWorker$2.run(MatlabWorker.java:79)
at com.mathworks.jmi.NativeMatlab.dispatchMTRequests(NativeMatlab.java:440)</i></p><p>I have full access to all of these places and matlab is not being very clear about what any of this means. I deleted the files that it generates in AppData/Roaming/Mathworks, but to no effect (I followed another post). All matlab-related folders have write permissions. I can't find any mention of this error while searching on Google so I'm completely stuck.</p><p>Does anyone have any idea what's going on?</p><p>Thanks!</p>Bogdan/matlabcentral/answers/contributors/3899132-bogdantag:mathworks.com,2005:Question/1597832014-10-23T07:59:44Z2014-10-23T13:58:44ZHow to delete specific lines from a txt file?<p>Hello, this is my problem:
Background: I am comparing 2 files that should match in the first column but one of the files skips some numbers, suppose (12,12), (13,13), (14,15)*, so until now I have use a code to find and display the mismatches on the screen and I manually delete the excess rows in the complete file and rerun the code until everything matchs.
Problem: Now usually I have used this with small files not correcting more than 10 mismatches, the problem is that I have a big data set with over 1000 of mismatches, so I need a way to delete the complete row of the "leftovers" in the txt file. Next is shown my coding:</p><pre class="language-matlab">%r is the number of total rows
%the first part is made for fileA and fileB storing in E and G matrices
fid = fopen('fileA.txt');
num_ints = 23;
num_rows = r;
format = [repmat('%f ', 1, num_ints)];
G = textscan(fid, format, num_rows);
G = [G{1:num_ints}];
fclose(fid);
</pre><pre class="language-matlab">for a = 1:1:r
if (E(a,1)~=G(a,1));
disp(E(a,1));
break
end
end
disp ('End of search');
</pre><p>As always thank you for your help!</p>Mario/matlabcentral/answers/contributors/4238010-mariotag:mathworks.com,2005:Question/1598232014-10-23T13:58:17Z2014-10-23T13:58:17ZHow to control a Release Gate with data computed in another Subsystem?<p>Hello everyone,</p><p>I am trying to do a traffic simulation with SimEvents (Matlab R2013b).
Since I have cars, that change their data continuously and entities, which are in a discrete event system I have to synchronize both parts. For a straight street my approach was to store the entities in a N-Server until the car has passed the straight and then let it out. The data of the car is stored in a matrix and each car has its own ID. Now the SimEvents system needs to check in the Matrix if the car already passed and then needs to open the release gate. If I try implementing this the function, which reads the memory matrix, is just executed once and the
I also tried using "Event To Timed Signale" Blocks before and after the function, which reads the memory. But then I get an algebraic loop error. If I break this loop with an delay, my data gets too old, which falsifies my simulation.
Do you have any ideas how to solve this? Is there a possibility to tell Simulink, to execute this function continuously?</p><p>Thanks for your help. I attached an example code.</p><p>Lucas</p>Lucas/matlabcentral/answers/contributors/3141362-lucastag:mathworks.com,2005:Question/1598212014-10-23T13:53:52Z2014-10-23T13:53:52ZDoesn't Gap Evaluation work with "Hamming" metric?<p>Hello all,</p><p>I tried to use Gap Value to evaluate K-means clustering. It returns error</p><pre class="language-matlab">eva = evalclusters(x,'kmeans','gap','distance','hamming','KList',[1:6])
</pre><pre class="language-matlab">Warning: Clustering reference data into 1 clusters using function 'getKmeansFunc/nested' generated the following error:
Non-binary data cannot be clustered using Hamming distance.
> In GapEvaluation>GapEvaluation.evalFunXref at 406
In GapEvaluation>GapEvaluation.getRefLogW at 562
In GapEvaluation>GapEvaluation.GapEvaluation at 376
In evalclusters at 172
Warning: Clustering reference data into 2 clusters using function 'getKmeansFunc/nested' generated the following error:
Non-binary data cannot be clustered using Hamming distance.
> In GapEvaluation>GapEvaluation.evalFunXref at 406
In GapEvaluation>GapEvaluation.getRefLogW at 562
In GapEvaluation>GapEvaluation.GapEvaluation at 376
In evalclusters at 172
</pre><p>and so on and so forth.</p><p>The data is definitely binary, cause I have applied K-means clustering (Hamming distance) successfully to the same data. It just doesn't work, when I evaluated it with Gap statistic. Can you help me out here? Thanks a lot!!</p>betty/matlabcentral/answers/contributors/5810523-bettytag:mathworks.com,2005:Question/1595092014-10-21T13:07:57Z2014-10-23T13:53:11ZEPS export problems in R2014b<p>I have recently upgraded to R2014b (Linux version), and now exporting figures to eps seems to have a strange bug. If I try the following from the command line, I get the expected outcome.
plot(1:3,2:4);print(gcf,'-depsc', 'testFromCommandLine.eps');</p><img src = "/matlabcentral/answers/uploaded_files/19777/Screenshot%20from%202014-10-21%2014:56:40.png"><p>However, if I run the exact same script from the editor window, I get an eps file with a graph that occupies the top left corner of the canvas.</p><img src = "/matlabcentral/answers/uploaded_files/19778/Screenshot%20from%202014-10-21%2014:58:31.png"><p>The only code in the script is:
close all;
plot(1:3,2:4);
print(gcf,'-depsc', 'testFromScript.eps')</p><p>The screenshots of the two generated eps files are embedded.</p><p>This happens in all these three cases: pressing the RUN button in the editor, selecting the code and running the selection and executing the script (just typing the script's name without .m) from the command line.</p>Remco/matlabcentral/answers/contributors/2009221-remcotag:mathworks.com,2005:Question/1596502014-10-22T11:45:35Z2014-10-23T13:52:26ZI am plotting the logistic growth model using ode45,But I am confused because I am getting oscillation while I should get a constant line so do you think there is another routine could I use it or I need to change something to get the right plot??<p>The model is :</p><p>dxdt=N0*x*(1-x/k)</p><p>What I am doing is :</p><p>tspan=0:0.001:100;</p><p>x0=0.1;</p><p>[t,x]=ode45('funname',tspan,x0)</p><p>figure</p><p>plot(t,x)</p>Avan Al-Saffar/matlabcentral/answers/contributors/5297065-avan-al-saffar