https://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-07-10T15:39:43Ztag:www.mathworks.com,2005:Question/1412792014-07-10T14:18:52Z2014-07-10T15:39:43ZRunning files: path problem?<p>I have a problem that has occurred on both my PC and Laptop versions of MATLAB. Neither will now run .m files which are entered at the command line. For example, let's set up a simple m file,
%check.m
x=2;
y=x^2</p><p>This is called check.</p><p>Previously I would just enter
>> check
on the command line and the file would run.</p><p>Now the response is:</p><p>??? Undefined function or variable 'check'.</p><p>Following previous threads, this seems to be related to the path that MATLAB looks for in finding the file, here check; but check is in the current folder displayed by MATLAB and is saved in that folder. Typing path responds as MATLABPATH, with the current folder listed first and then a number of other paths differing only in referring to \toolbox\matlab\general etc.</p><p>My puzzle is threefold:
I. Why won't the files now execute from the command line.
2. Have I inadvertently changed the path, if so how?
3. Has MATLAB changed this routing to find the file compared to previous versions?</p><p>I have resorted to an old version of MATLAB to run my files, where no such problems have occurred, but some tips on getting the recent versions working would be very helpful.</p>Kerry/matlabcentral/answers/contributors/2449337-kerrytag:www.mathworks.com,2005:Question/1395572014-06-30T20:20:16Z2014-07-10T15:38:43ZBlurring/Filling in color on jpeg image.<p>Hi,</p><p>I'm working with painmaps (see example attached), and I'm trying to shade in the red areas. As you can see the red is scribbled on and there are white spaces within, I'd like to take the outer extremities of the red scribbling and fill in everything inside of it red, so that it's one solid block of red. This is so that I can quantify the shaded pixels for analytical purposes. Any help with this would be much appreciated. I was thinking that perhaps imfill or morphological closing could be used, but I'm struggling to make either option work.</p><p>Thanks,
Matt</p>Matthew Alston/matlabcentral/answers/contributors/5379885-matthew-alstontag:www.mathworks.com,2005:Question/1412862014-07-10T15:26:18Z2014-07-10T15:38:18Zhow to calculate standard deviation of 1D array?<p>i have an array A.</p><pre class="language-matlab">A=[1 2 3 4];
s=std(A);
</pre><p>Error: Index exceeds matrix dimensions.</p><ul><li>sometimes std says: Subscript indices must either be real positive integers or logicals.</li><li>and also what is the difference in std and std2.</li></ul>Ayush/matlabcentral/answers/contributors/5176143-ayushtag:www.mathworks.com,2005:Question/1412802014-07-10T14:24:32Z2014-07-10T15:36:40ZGUI- "Attempt to reference field of non-structure array." Error with varargout and using red x to close<p>A similar question was already asked but the link to the solution ( <a href = "http://www.mathworks.com/support/solutions/data/1-193LD.html?solution=1-193LD">http://www.mathworks.com/support/solutions/data/1-193LD.html?solution=1-193LD</a> ) has expired I think because I can't view it so I figured I would ask it again since similar questions don't seem to relate to varargout:</p><p>Error using waitfor
Error while evaluating uicontrol Callback</p><p>Attempt to reference field of non-structure array.</p><p>Error in SaveMethod>SaveMethod_OutputFcn (line 207)
varargout{1} = handles.output;</p><p>Error in gui_mainfcn (line 263)
[varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);</p><p>Error in SaveMethod (line 40)
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});</p><p>I get the error when I try to close my GUI window with the red x in the corner (as opposed to a back button I usually use to close). I also tried to include a uiwait in my opening and then uiresume in my output functions but I still got the same error.</p><p>Any solutions?</p><p>P.S. This is my outputfcn:
varargout{1} = handles.output;
set(handles.figure1,'Visible','off')</p>Megna/matlabcentral/answers/contributors/2516583-megnatag:www.mathworks.com,2005:Question/1412572014-07-10T10:37:14Z2014-07-10T15:33:36ZHow to implement a tree <p>So i am really new at matlab and didnt find any usefull link or tutorial. I wanna creat a tree structure can i do this in matlab? some key commands? a usefull link? thanks in advance</p>laplace laplace/matlabcentral/answers/contributors/3928177-laplace-laplacetag:www.mathworks.com,2005:Question/1410852014-07-09T10:42:09Z2014-07-10T15:32:48ZHow to barplot with standard deviation?<p>I've got following code so far:</p><pre class="language-matlab">if true
% code
end
load('Mean.mat') % Mean contains all mean values and consists of 5 rows
x = [time]; % define x-axis
y = [IC1,IC2,IC3,IC4]; % define y-axis
figure;
hBars = bar(y,1.0); % create bar plot with y;
set(gca,'XTickLabel',{'Baseline','0,1','0.2','0.3','0.4','0.5'});
% set ticks and tick labels
xlabel('Time');
ylabel('Impulse');
hold on;
load('standarddev.mat') % standarddev contains all calculated standard deviation and consists of 5 %rows
std = [sd1,sd2,sd3,sd4,sd5]; % define y-axis
errorbar(x,y,std);
title('Impulse');
legend('a','b','c','d','Location','SouthEastOutside')
% put in lower right
</pre><p>The plot itself works fine. I'd like to include the errorbars for the standard deviation as well but that unfortunately doesn't work at the moment. I've already had a look at the MATLAB Documentation Center bt without success.</p><p>Any help would be appreciated.</p>Pinga/matlabcentral/answers/contributors/5424090-pingatag:www.mathworks.com,2005:Question/1412782014-07-10T14:05:37Z2014-07-10T15:30:53ZCalculating PDF from CDF<p>I calculated CDF manually, because I want to be able to see the progression. So I calculated multiple CDF's over a range, and have all the CDF's in a vector. I want to calculate PDF from CDF by subtracting the previous CDF from the current CDF, and again have all the calculated PDF's in vector form. How would I go about writing this? Thank you.</p><p>mu = 1.5;</p><p>sigma = .11*mu</p><p>delta = [0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.1
0.11
0.12
0.13
0.14
0.15
0.16
0.17
0.18
0.19
0.2
0.21
0.22
0.23
0.24
0.25
0.26
0.27
0.28
0.29
0.3
0.31
0.32
0.33
0.34
0.35
0.36
0.37
0.38
0.39
0.4
0.41
0.42
0.43
0.44
0.45
0.46
0.47
0.48
0.49
0.5
0.51
0.52
0.53
0.54
0.55
0.56
0.57
0.58
0.59
0.6
0.61
0.62
0.63
0.64
0.65
0.66
0.67
0.68
0.69
0.7
0.71
0.72
0.73
0.74
0.75
0.76
0.77
0.78
0.79
0.8
0.81
0.82
0.83
0.84
0.85
0.86
0.87
0.88
0.89
0.9
0.91
0.92
0.93
0.94
0.95
0.96
0.97
0.98
0.99
1
1.01
1.02
1.03
1.04
1.05
1.06
1.07
1.08
1.09
1.1
1.11
1.12
1.13
1.14
1.15
1.16
1.17
1.18
1.19
1.2
1.21
1.22
1.23
1.24
1.25
1.26
1.27
1.28
1.29
1.3
1.31
1.32
1.33
1.34
1.35
1.36
1.37
1.38
1.39
1.4
1.41
1.42
1.43
1.44
1.45
1.46
1.47
1.48
1.49
1.5
1.51
1.52
1.53
1.54
1.55
1.56
1.57
1.58
1.59
1.6
1.61
1.62
1.63
1.64
1.65
1.66
1.67
1.68
1.69
1.7
1.71
1.72
1.73
1.74
1.75
1.76
1.77
1.78
1.79
1.8
1.81
1.82
1.83
1.84
1.85
1.86
1.87
1.88
1.89
1.9
1.91
1.92
1.93
1.94
1.95
1.96
1.97
1.98
1.99
2
]</p><p>cdf = .5*[1+erf((delta-mu)/(sqrt(2*sigma^2)))]</p><p>//pdf...?</p>Peter/matlabcentral/answers/contributors/4617450-petertag:www.mathworks.com,2005:Question/1408992014-07-08T12:30:52Z2014-07-10T15:30:09ZHow to merge multiple scripts in MATLAB<p>Hi,</p><p>I am running an analysis using SPM, and want to run multiple batches at once. One way to do this is to copy and paste each subject's batch script into a new one and run them together. However, this is quite time consuming considering I have 155 batches!</p><p>Therefore, I was wondering if there is an easier way to merge multiple script files in MATLAB?</p><p>Thank you,
mfazal</p>Mobeen/matlabcentral/answers/contributors/5450851-mobeentag:www.mathworks.com,2005:Question/993472010-12-29T20:26:00Z2014-07-10T15:25:10ZHow do I determine which product corresponds with the increment lines in my license file and why does my license file contain a "NOTICE" tag?<p>Looking at my new license file, it contains a "NOTICE tag. For example:</p><pre class="language-matlab">INCREMENT MATLAB MLM 24 01-jan-0000 1 ABCDEFGH123456789 \
DUP_GROUP=UH asset_info=123456 ISSUED=15-Dec-2010 \
NOTICE=product=MATLAB SN=123456
</pre><p>Why is this tag added and what does it do?</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/1407792014-07-07T19:47:18Z2014-07-10T15:23:48ZHow can I compute p0 for given values of K,c,lambda,mu ? Thanks in advance! <img src = "/matlabcentral/answers/uploaded_files/15104/sum.JPG"><pre class="language-matlab">lambda=3.1;
mu=0.9;
c=4;
B=5;
K=c+B;
syms n
p1=symsum(1/factorial(n)*((lambda/mu))^n,n,0,c);
p2=((lambda/mu).^c)./factorial(c)+symsum((lambda./c*mu)^(n-c),n , (c+1), K);
p0=(p1+p2)^(-1);
</pre><p>Possibly: <a href = "http://www.mathworks.com/matlabcentral/answers/162-how-do-i-simplify-a-symbolic-expression-into-numeric-output">http://www.mathworks.com/matlabcentral/answers/162-how-do-i-simplify-a-symbolic-expression-into-numeric-output</a> ?</p>Tasos Charitonidis/matlabcentral/answers/contributors/5366685-tasos-charitonidistag:www.mathworks.com,2005:Question/1411912014-07-10T01:09:59Z2014-07-10T15:23:06ZHow to plot serial data against time<p>I have an arduino sending serial data every 2 seconds to the serial monitor and Matlab code will read from that serial monitor and plot a graph. The graph plots a value every 2 seconds but how do i make the x -axis equal to time so that the graph shows data is plotted every 2 seconds.</p>Jack/matlabcentral/answers/contributors/5436197-jacktag:www.mathworks.com,2005:Question/1412842014-07-10T15:11:21Z2014-07-10T15:18:53Zassigning a variable name with prefix from a loop read to an array <p>for j=109:110
% create a filename for loop read
ExcelFileName = sprintf('%d_IF.csv', j);
ExcelSheetName = sprintf('%d_IF',j);
%
Mod_IF = xlsread(ExcelFileName,ExcelSheetName,'B22:B100021');
%
end
% what I want to do is read in 109_IF.csv, 109_IF sheet from B22 to B100021
% As far as I can tell that is occuring because I can look at Mod_IF and
% it has the correct values.
%
% I would like to save the data into Mod_IF_109 on the first loop
% and then save the data on the second read into Mod_IF_110 and so on
%
% I have not found a way to do that, I have tried eval, S., newname
% and so on, but each time I tried to access the data outside the
% loop an error occurs that says function or variable Mod_IF_109 is undefine
% and I do not see Mod_IF_109 array in the workspace being created.
%
% Looking at the FAQs and the other have, the solutions are close
% but I have not been able to get them to get past the error, in fact
% the above came from a FAQ but the FAQ did not elaborate on how to
% save the data into an array that is identified by the j value.
%
% Using a multi-column array is NOT an option i.e (10000x(number of
% reads in the loop) for various reasons
% Thanks for any advance
%Regards
%Philip</p>Philip/matlabcentral/answers/contributors/4915423-philiptag:www.mathworks.com,2005:Question/1412852014-07-10T15:12:00Z2014-07-10T15:12:00ZCombine all Output Graphs<p>Hi,</p><p>I have output graphs "Torque over time" from 3 revolute joints in Simmechanics. Is it possible to combine all these graphs as one final graph. For example, I want the values for 0 - 2s from first graph, 2 - 4s from second graph and 4 - 6s from the last graph. And put these values as one final graph from 0 - 6 s. Is it pssible to do this?</p><p>Best, Vish.</p>Vishnu/matlabcentral/answers/contributors/5293415-vishnutag:www.mathworks.com,2005:Question/1411682014-07-09T20:03:06Z2014-07-10T15:09:45ZFirst Run Clock Time from Memory Block<p>Hello,
I am new to Simulink world, and trying to build an algorithm which depends on the simulated clock timing. Everything runs fine, except the very first time step.
My algorithm uses a Memory block with clock input to detect the timing between two pulses of a crank. When I run the simulation, since the memory block initialization value is set to be 0, it gives wrong pulse time at the first simulated time step. Is it possible for the memory block to output the time when its called at the first simulation step, as an initial value?</p>PAR/matlabcentral/answers/contributors/5086012-partag:www.mathworks.com,2005:Question/1412832014-07-10T15:08:09Z2014-07-10T15:08:09ZHow can i save and accumulate the real-time data retrieval in my Oracle Express database? <p>I am working with the datafeed toolbox and currently retrieving data from Bloomberg in real time. Additionally i have the Oracle Express database installed. Now, I would like to save and accumulate the data I retreive from the Datafeed in the database. How can i proceed. I am completely new to Matlab but i manage basic commands. Any help highly appreciated.</p>Paul/matlabcentral/answers/contributors/4714160-paultag:www.mathworks.com,2005:Question/20012011-02-25T00:37:19Z2014-07-10T15:07:11ZWhat matlab easter eggs do you know?<p>Please post the easter eggs that you have found so far if they aren't already posted by someone else.</p>
<p>Let's try to make a good Matlab easter egg list because it seems that there isn't one.</p>
<p>What should be posted:</p>
<ul>
<li>Unexpected but intentional behaviour</li>
<li>Special things that the programmers left for us to discover</li>
<li>Extra code inside a function that can be used for other purposes</li>
<li>Hidden pictures and audio clips</li>
</ul>
<p>What shouldn't be posted:</p>
<ul>
<li>Repeated Easter Eggs, if someone already posted it please don't repeat</li>
<li>Bugs in functions that cause trouble and might be fixed in later versions</li>
<li>Matlab games that come with the program unless they aren't mentioned in the documentation (the games are in the other demos, try the xpbombs and fifteen, you can even see the code for both games)</li>
</ul>Paulo Silva/matlabcentral/answers/contributors/2021205-paulo-silvatag:www.mathworks.com,2005:Question/1411842014-07-09T22:31:47Z2014-07-10T15:02:39ZError using mex No supported compiler or SDK was found.<p>Hello All,</p><p>I've just installed Microsoft Visual Studio Professional 2013, and Matlab R2014a on my laptop, but when I use the command mex -startup or mex -v arrayProduct.c, I get the following error message:</p><p>Error using mex
No supported compiler or SDK was found. For options, visit <a href = "http://www.mathworks.com/support/compilers/R2014a/win64">http://www.mathworks.com/support/compilers/R2014a/win64</a>.</p><p>Can anybody tell what the cause of this error is or how I can link the mex compiler with visual studio 2013?</p><p>Thanks alot.</p>margol/matlabcentral/answers/contributors/5441036-margoltag:www.mathworks.com,2005:Question/1412822014-07-10T14:54:53Z2014-07-10T14:54:53ZGUI profiler: slowest at FileOpenChooser.doShowDialog<p>I am making a fairly large GUI (not a whole lot of data, but different GUI screens and a lot of tables, buttons, etc.), and as I add more functionality, it just gets slower and slower. I just ran the profiler, and the highest "self-time" section was FileOpenChooser.doShowDialog at 9.062s. I wonder what might be the cause for this - is it just the amount of GUI buttons and tables that I use? I'm not sure what information I can provide to help further on here.</p><p>As a note, I'm a bit confused about using the uitabs (so I'm not currently doing that),but I like using GUIDE since there are so many parts to the GUI, so I can set it up visually which I like. As the GUI is now, it's like a poor version of tabs. Based on what configuration the user seects, a different set of uipanels will become visible, so when I see the GUI in guide, it's just all the uipanels overlapping. I realize this is not good. I'd like to be able to use guide to make my different screens for the user in a more efficient way, but I'm just not sure what the best method is.I don't want one GUI to close and another to open -- it should be a seamless transition.</p><p>Sorry this is sort of a ramble. Any input would be appreciated.</p>katerina/matlabcentral/answers/contributors/5398465-katerinatag:www.mathworks.com,2005:Question/1412262014-07-10T08:10:27Z2014-07-10T14:54:22ZRotating a 3D image?<p>What code could I use in order to be able to rotate a 3d image of a brain? Im using Matlab 2007 version, thanks in advance</p>Jack/matlabcentral/answers/contributors/5442683-jacktag:www.mathworks.com,2005:Question/1412712014-07-10T12:50:36Z2014-07-10T14:53:54ZWhat are the frequencies when N in fft(x,N) is odd?<p>I know when N is even, fft(x,N) corresponds to frequencies 0,df,...,N/2*df,-(N/2-2)*df,...,-df.</p><p>What about if N is odd?</p>Ray Lee/matlabcentral/answers/contributors/1411057-ray-leetag:www.mathworks.com,2005:Question/1411242014-07-09T15:30:44Z2014-07-10T14:49:10ZDifferent outcome by using self time iteration and ode15s.<p><b>I am currently under the project of parameter estimation of bioprocess fermentation. I already had the code of modelling which shows below with the graph shows below. However, I need to implement my model in ode15 in order to implement in parameter estimation method later. But I cant get the same result when using ode15s.</b></p><p><b>The code of self-time iteration:</b></p><p>function opti</p><pre class="language-matlab">%Declare bioreactor parameter
global ux Ks K1 K2 H Kox KI Ag Ad Ea Ed R u X uxp I Ki K D dH dS dCp Temp0...
dGTS Pn Pc Ysx mx S rol Di V Vs Clx qO2 Pg Kla Cl Fj Vj Tempj0 U Ah rolj Cpj...
Tempj YH Cp Temp Kd Kn t tstart tstop N
</pre><pre class="language-matlab">ux = 0.1027; %maximum specific growth rate (per h)
</pre><pre class="language-matlab">Ks = 7.5; %half saturation constant (g/l)
</pre><pre class="language-matlab">K1 = 7.05*10^-10; %constant (Molar)
</pre><pre class="language-matlab">K2 = 6.86*10^-8; %constant (Molar)
</pre><pre class="language-matlab">H = 10^(-7.1); %ion hydrogen concentration (M)
</pre><pre class="language-matlab">Kox = 7.104*10^-7; %oxygen limitation constant (g/l
)
KI= 0.001; %inhibition constant due to excessive subtrate (g/l)
</pre><pre class="language-matlab">Ag = 10^7.9; %Arrhenius constant for growth
</pre><pre class="language-matlab">Ad = 10^10; %Arrhenius constant for death
</pre><pre class="language-matlab">Ea = 10000; %activation energy for growth (cal/mol)
</pre><pre class="language-matlab">Ed = 80000; %activation energy for death (cal/mol)
</pre><pre class="language-matlab">R = 1.987; %gas constant (cal/mol K)
</pre><pre class="language-matlab">uxp = 0.5872; %maximum specific production rate (per h)
</pre><pre class="language-matlab">I = 0.162; %inducer concentration (g/l)
</pre><pre class="language-matlab">Ki = 0.001; %saturation constant for inducer (g/l)
</pre><pre class="language-matlab">K = 0.0625; %protein degradation rate
</pre><pre class="language-matlab">D = 1.65*10^14; %preexponential factor (per h)
</pre><pre class="language-matlab">dH = 9.4*10^3; %change in enthalpy (cal/mol)
</pre><pre class="language-matlab">dS = -0.01*10^3; %change in entropy (cal/mol)
</pre><pre class="language-matlab">dCp = -0.32*10^3; %change in the heat capacity of the protein between fold and unfold state
</pre><pre class="language-matlab">Temp0 = 295; %reference temperature (K)
</pre><pre class="language-matlab">Ysx = 0.0105; %yield coefficient (g/g)
</pre><pre class="language-matlab">mx = 0.003; %cell maintenance coefficient
</pre><pre class="language-matlab">rol = 998.23; %density medium (g/l)
</pre><pre class="language-matlab">Di = 46*10^-3; %impeller diameter (m), Rushton
</pre><pre class="language-matlab">V = 1.5; %volume culture (l)
</pre><pre class="language-matlab">Vs = 1.1372; %oxygen superficial velocity (m/s)
</pre><pre class="language-matlab">Clx = 7*10^-3; %saturated DO concentration (g/l)
</pre><pre class="language-matlab">qO2 = 384*10^-3; %specific uptake rate of oxygen (g/g h)
</pre><pre class="language-matlab">Fj = 0.001; %flowrate cooling water (l/h)
</pre><pre class="language-matlab">Vj = 0.85; %volume cooling water (l)
</pre><pre class="language-matlab">Tempj0 = 293; %inlet temperature of cooling water (K)
</pre><pre class="language-matlab">U = 3.6482*10^4; %overall heat transfer coefficient (cal/h m2 K)
</pre><pre class="language-matlab">Ah = 0.606; %contacted surface area (m2)
</pre><pre class="language-matlab">rolj = 997.3658; %density cooling water (g/l)
</pre><pre class="language-matlab">Cpj = 1; %heat capacity cooling water (cal/ g K)
</pre><pre class="language-matlab">YH = 0.42*10^-3; %1/YH is metabolic heat evolved per g biomass (g/cal)
</pre><pre class="language-matlab">Cp = 1; %heat capacity of medium (cal/ g K)
</pre><pre class="language-matlab">N = 10/3; %agitation speed (rev/s)
</pre><pre class="language-matlab">Kd = 0.02; %specific death rate (per h)
</pre><pre class="language-matlab">%----------------------------------------------------
</pre><pre class="language-matlab">%initial value
</pre><pre class="language-matlab">X=0.12;
</pre><pre class="language-matlab">S=50;
</pre><pre class="language-matlab">Cl=1.4*10^-3;
</pre><pre class="language-matlab">Temp=310;
Tempj=293;
Pn=0;
Pc=0;
</pre><pre class="language-matlab">t=0.005;
</pre><pre class="language-matlab">tstart=0;
</pre><pre class="language-matlab">tstop=60;
</pre><pre class="language-matlab">maxsave=10;
</pre><pre class="language-matlab">nsave=maxsave+1;
</pre><pre class="language-matlab">time=0;
</pre><pre class="language-matlab">cmax=round(tstop/t);
</pre><pre class="language-matlab">kont=0;
</pre><pre class="language-matlab">%controller data
</pre><pre class="language-matlab">kc1=70;
</pre><pre class="language-matlab">ti1=0.5;
</pre><pre class="language-matlab">taud1=1.6;
</pre><pre class="language-matlab">sp1=293;
</pre><pre class="language-matlab">er1nm1=0;
</pre><pre class="language-matlab">Tnm1=293;
</pre><pre class="language-matlab">Tnm2=293;
</pre><pre class="language-matlab">%while loop to calculate transient response from tstart to tstop
</pre><pre class="language-matlab">while time<tstop
</pre><pre> time=time+t;</pre><pre> nsave=nsave+1;</pre><pre> %state variables
u=(ux*S)/((Ks+S)*(1+K1/H+H/K2)*(S+KI+(S^2)/Ks)*(Kox+1.4*10^-3))*(Ag*exp(-Ea/(R*Temp))-Ad*exp(-Ed/(R*Temp)));
dGTS = dH-Temp*dS+dCp*(Temp-Temp0-Temp*log(Temp/Temp0));
Pg = 0.4*6*rol*N^3*Di^5;
Kla = 0.0195*((Pg/V)^0.55)*((Vs)^0.64)*(1+2.12*X+0.2*X^2)^-0.25;
Kn = 111.3*exp (-((Temp-313.3)/7.42)^2);
%models
X = X+t*((u-Kd)*X);
S = S+t*(u/Ysx+mx)*(-X);
Cl = Cl+t*(Kla*(Clx-Cl)-qO2*X);
Temp = Temp+t*((u*X)/(YH*rol*Cp)-(U*Ah)/(V*rol*Cp)*(Temp-Tempj));
Tempj = Tempj+t*((Fj/Vj)*(Tempj0-Tempj)+(U*Ah)/(rolj*Vj*Cpj)*(Temp-Tempj));
Pn = Pn+t*((uxp*I)/(I+Ki)*u*X-K*Pn);
Pc = Pc+t*((D*exp(-dGTS/(R*Temp)))*Pn-Kn*Pc);</pre><pre> %controller
errorn1=(sp1-Tempj);
if time==tstart,
Tnm1=sp1;
Tnm2=Tnm1;
end</pre><pre> deltaFj=kc1*(errorn1-er1nm1+(t*errorn1)/ti1-...
(taud1*(Tempj-2*Tnm1+Tnm2)/t)); </pre><pre> Fj=Fj+deltaFj;</pre><pre> Fjmax = 250;
Fjmin = 0.001;</pre><pre> if Fj>=Fjmax
Fj=Fjmax;
end</pre><pre> if Fj<=Fjmin
Fj=Fjmin;
end
er1nm1=errorn1;
Tnm2=Tnm1;
Tnm1=Tempj;</pre><pre> %save the output variables every maxsave times
if nsave>=maxsave
kont=kont+1;
Y1(1,kont)=X;
Y2(1,kont)=S;
Y3(1,kont)=u;
Y4(1,kont)=Temp;
Y5(1,kont)=Tempj;
Y6(1,kont)=Pn;
Y7(1,kont)=Pc;
Y8(1,kont)=Fj;
T(1,kont)=time;
nsave=0;
end</pre><p>figure (3), plot(T,Y1)</p><p>xlabel ('post induction time hr')</p><p>ylabel ('biomass g/l')</p><p>title('biomass vs time')</p><p><b>And the graph obtained is shown as below.</b></p><img src = "/matlabcentral/answers/uploaded_files/15191/untitled.jpg"><p><b>However, when I change another method which is using Runge-kutta ode15s method to undergo the coding, it comes with totally different graph.</b></p><p><b>The code of model:</b></p><pre> function dx = cgtase(~, x)</pre><pre> dx = [0;0;0;0;0;0;0;];</pre><pre class="language-matlab">%Declare bioreactor parameter
global ux Ks K1 K2 H Kox KI Ag Ad Ea Ed R u uxp I Ki K D dH dCp Temp0...
</pre><pre class="language-matlab">dGTS Ysx mx rol Di V Vs Clx qO2 Pg Kla Fj Vj Tempj0 U Ah rolj Cpj...
</pre><pre class="language-matlab">YH Cp Kd Kn t tstart tstop N
</pre><pre class="language-matlab">ux = 0.1027; %maximum specific growth rate (per h)
</pre><pre class="language-matlab">Ks = 7.5; %half saturation constant (g/l)
</pre><pre class="language-matlab">K1 = 7.05*10^-10; %constant (Molar)
</pre><pre class="language-matlab">K2 = 6.86*10^-8; %constant (Molar)
</pre><pre class="language-matlab">H = 10^(-7.1); %ion hydrogen concentration (M)
</pre><pre class="language-matlab">Kox = 7.104*10^-7; %oxygen limitation constant (g/l)
</pre><pre class="language-matlab">KI= 0.001; %inhibition constant due to excessive subtrate (g/l)
</pre><pre class="language-matlab">Ag = 10^7.9; %Arrhenius constant for growth
</pre><pre class="language-matlab">Ad = 10^10; %Arrhenius constant for death
</pre><pre class="language-matlab">Ea = 10000; %activation energy for growth (cal/mol)
</pre><pre class="language-matlab">Ed = 80000; %activation energy for death (cal/mol)
</pre><pre class="language-matlab">R = 1.987; %gas constant (cal/mol K)
</pre><pre class="language-matlab">uxp = 0.5872; %maximum specific production rate (per h)
</pre><pre class="language-matlab">I = 0.162; %inducer concentration (g/l)
</pre><pre class="language-matlab">Ki = 0.001; %saturation constant for inducer (g/l)
</pre><pre class="language-matlab">K = 0.0625; %protein degradation rate
</pre><pre class="language-matlab">D = 1.65*10^14; %preexponential factor (per h)
</pre><pre class="language-matlab">dH = 9.4*10^3; %change in enthalpy (cal/mol)
</pre><pre class="language-matlab">dS = -0.01*10^3; %change in entropy (cal/mol)
</pre><pre class="language-matlab">dCp = -0.32*10^3; %change in the heat capacity of the protein between fold and unfold state
</pre><pre class="language-matlab">Temp0 = 295; %reference temperature (K)
</pre><pre class="language-matlab">Ysx = 0.0105; %yield coefficient (g/g)
</pre><pre class="language-matlab">mx = 0.003; %cell maintenance coefficient
</pre><pre class="language-matlab">rol = 998.23; %density medium (g/l)
</pre><pre class="language-matlab">Di = 46*10^-3; %impeller diameter (m), Rushton
</pre><pre class="language-matlab">V = 1.5; %volume culture (l)
</pre><pre class="language-matlab">Vs = 1.1372; %oxygen superficial velocity (m/s)
</pre><pre class="language-matlab">Clx = 7*10^-3; %saturated DO concentration (g/l)
</pre><pre class="language-matlab">qO2 = 384*10^-3; %specific uptake rate of oxygen (g/g h)
</pre><pre class="language-matlab">Fj = 0.001; %flowrate cooling water (l/h)
</pre><pre class="language-matlab">Vj = 0.85; %volume cooling water (l)
</pre><pre class="language-matlab">Tempj0 = 293; %inlet temperature of cooling water (K)
</pre><pre class="language-matlab">U = 3.6482*10^4; %overall heat transfer coefficient (cal/h m2 K)
</pre><pre class="language-matlab">Ah = 0.606; %contacted surface area (m2)
</pre><pre class="language-matlab">rolj = 997.3658; %density cooling water (g/l)
</pre><pre class="language-matlab">Cpj = 1; %heat capacity cooling water (cal/ g K)
</pre><pre class="language-matlab">YH = 0.42*10^-3; %1/YH is metabolic heat evolved per g biomass (g/cal)
</pre><pre class="language-matlab">Cp = 1; %heat capacity of medium (cal/ g K)
</pre><pre class="language-matlab">N = 10/3; %agitation speed (rev/s)
</pre><pre class="language-matlab">Kd = 0.02; %specific death rate (per h)
</pre><pre class="language-matlab">%----------------------------------------------------
</pre><pre class="language-matlab">%initial value
%x(1)=0.12;
%x(2)=50;
%x(3)=1.4*10^-3;
%x(4)=310;
%x(5)=293;
%x(6)=0;
%x(7)=0;
</pre><pre class="language-matlab">t=0.3;
tstart=0;
tstop=60;
</pre><pre class="language-matlab">time=0;
</pre><pre class="language-matlab">%controller data
kc1=70;
ti1=0.5;
taud1=1.6;
sp1=293;
er1nm1=0;
Tnm1=293;
Tnm2=293;
</pre><pre> %state variables
u=(ux*x(2))/((Ks+x(2))*(1+K1/H+H/K2)*(x(2)+KI+(x(2)^2)/Ks)*(Kox+1.4*10^-3))*(Ag*exp(-Ea/(R*x(4)))-Ad*exp(-Ed/(R*x(4))));
dGTS = dH-x(4)*dS+dCp*(x(4)-Temp0-x(4)*log(x(4)/Temp0));
Pg = 0.4*6*rol*N^3*Di^5;
Kla = 0.0195*((Pg/V)^0.55)*((Vs)^0.64)*(1+2.12*x(1)+0.2*x(1)^2)^-0.25;
Kn = 111.3*exp (-((x(4)-313.3)/7.42)^2);</pre><pre> %models
dx(1) = (u-Kd)*x(1);
dx(2) = (u/Ysx+mx)*(-x(1));
dx(3) = (Kla*(Clx-x(3))-qO2*x(1));
dx(4) = ((u*x(1))/(YH*rol*Cp)-(U*Ah)/(V*rol*Cp)*(x(4)-x(5)));
dx(5) = ((Fj/Vj)*(Tempj0-x(5))+(U*Ah)/(rolj*Vj*Cpj)*(x(4)-x(5)));
dx(6) = ((uxp*I)/(I+Ki)*u*x(1)-K*x(6));
dx(7) = (D*exp(-dGTS/(R*x(4))))*x(6)-Kn*x(7);</pre><pre> %controller
errorn1=(sp1-x(5));
if time==tstart,
Tnm1=sp1;
Tnm2=Tnm1;
end</pre><pre> deltaFj=kc1*(errorn1-er1nm1+(t*errorn1)/ti1-...
(taud1*(x(5)-2*Tnm1+Tnm2)/t)); </pre><pre> Fj=Fj+deltaFj;</pre><pre> Fjmax = 250;
Fjmin = 0.001;</pre><pre> if Fj>=Fjmax
Fj=Fjmax;
end</pre><pre> if Fj<=Fjmin
Fj=Fjmin;
end
er1nm1=errorn1;
Tnm2=Tnm1;
Tnm1=x(5);</pre><p><b>The code of ode15s to run the model:</b></p><pre class="language-matlab">options = odeset('RelTol', 1e-4, 'NonNegative', [1 2 3]);
</pre><pre class="language-matlab">[t,x] = ode15s('cgtase', [0 60], [0.12 50 1.4*10^-3 310 293 0 0], options);
plot(t,x(1:226,1));
</pre><p><b>The graph become:</b></p><img src = "/matlabcentral/answers/uploaded_files/15193/untitled2.jpg"><p><b>Can anyone point out my mistakes on using the ode15s? Thanks in advance!!</b></p>Bendo Voon/matlabcentral/answers/contributors/5423848-bendo-voontag:www.mathworks.com,2005:Question/1412812014-07-10T14:48:57Z2014-07-10T14:48:57Zcan any one tell me some thing how to use the lasso function <p>can any tell me some thing about the lasso function ..</p>Abhishek sadasivan/matlabcentral/answers/contributors/2454716-abhishek-sadasivantag:www.mathworks.com,2005:Question/1412422014-07-10T09:39:00Z2014-07-10T14:47:35Zhow can use optimization without using optimization tool box from the matlab simulink<p>i want to optimized the model which caLculate the total power consumption in residence.
i want to use the optimization but i don't have the access to the matlab optimization tool box. can anyone tell me how to do that.
thank you!</p>charith/matlabcentral/answers/contributors/4695080-charithtag:www.mathworks.com,2005:Question/1410792014-07-09T10:09:43Z2014-07-10T14:42:17ZForecasting with an AR(8) model<p>Hi, I am totally newly in Matlab and I have a question.</p><p>I have a time series and I want to apply an AR(8) model to forecast the next 12 observations.</p><p>I dont think that I could understand/follow the Mathworks instructions.</p><p>Any help??</p><p>Thank you!</p>Panty/matlabcentral/answers/contributors/5440662-pantytag:www.mathworks.com,2005:Question/1412012014-07-10T03:55:05Z2014-07-10T14:39:02ZI have a data that can be varied by the user using edit box . How can I output it on excel<p>I have created a panel consisting of 3 script box and corresponding 3 edit box in GUI, . I am also using 2 push buttons Save and Cancel.Now, when I run the code and when I type any value in edit box and click save button,it should save it in Excel sheet cell by cell i.e 1st edit box's value should be stored in 1st cell(say A1),2nd in 2nd cell(A2) and so on.</p><p>Please help me.</p>KRUNAL/matlabcentral/answers/contributors/5309685-krunaltag:www.mathworks.com,2005:Question/1412432014-07-10T09:49:42Z2014-07-10T14:37:25ZImportdata does not import whole .txt file<p>I'm encountering a problem importing a .txt file containing mass spectrometry data. Somewhere along the way it just stops importing the remaining part of my .txt file (in total over 777.000 lines)</p><p>The data I'm trying to import describes a scan event from the mass spectrometer. The header (from 'BEGIN IONS' to 'SCANS=scannumber') describes certain properties of the scan event. The numbers between 'SCANS=scannumber' and 'END IONS' describe the spectrum (the actual data, but worthless without the header); the first column being <b>m/z values</b> , the second <b>ion intensities</b> .</p><p>My data looks lik this (this is one scan event):</p><pre class="language-matlab">BEGIN IONS
TITLE=Spectrum2667 scans: 5993,
PEPMASS=897.52844 17418.17383
CHARGE=2+
RTINSECONDS=3127
SCANS=5993
176.86790 128.299
181.97141 139.498
221.90227 139.841
341.23862 982.842
END IONS
</pre><p>I want to extract certain scan events based on their scannumber; another script tells me which ones to extract from this file. But, MATLAB is not importing all my scans. Therefore I am missing some of the data (and my other script gives an error, because the scan number it is looking for is not present).</p><p>I have just over 6000 of these scans in one .txt file. For some reason, MATLAB stops somewhere near the end of my file. At a certain scan event, it stops halfway the list describing the spectrum. The code I use to import the data is:</p><pre class="language-matlab">List = importdata('MyData.txt');
</pre><p>Because I just need a list of all the scan events and write them to a new file after I have extracted the scan events that I want, it is of no importance to import the file in two columns or split the header etc; I just want the complete list all the way to the end of my .txt file.</p><p>I've looked in my .txt file, but there is no different space and/or tab format at this particular line in the .txt file.</p><p>If someone could help me solve my problem, I would be very happy.</p>Luuk van Oosten/matlabcentral/answers/contributors/3115978-luuk-van-oostentag:www.mathworks.com,2005:Question/1412612014-07-10T11:07:25Z2014-07-10T14:35:05ZIn a multiclass classification problem using Random Forest/Tree Bagger. How would I determine the most important features for each particular class?<p>Is there a quick and easy way to do this or will it require modification of the code?</p>David/matlabcentral/answers/contributors/4667661-davidtag:www.mathworks.com,2005:Question/1379062014-06-27T07:43:43Z2014-07-10T14:31:16ZBest way for manipulating multivariate polynomials<p>I am looking for a good way to manipulate multivariate polynomials in Matlab. The purpose of this question is very global. Currently, I am manipulating some matrices of polynomials in MATLAB (with currently 2 variables). To simplify this manipulation I split each matrix into four new matrices:</p><pre> - One for defining the coefficient: `C`
- One for defining an exponent: `E` (see below)
- One for defining the power of the first variable `X`: `MX`
- One for defining the poser of the second variable `Y`: `MY`</pre><p>Thus you can evaluate polynomial matrix by this way `C./h^E.*X.^MX.*Y.^MY`. For some reason, sometimes each component of the polynomial matrix can be a sum of some monomials. In this case, I use some nD-arrays (and `sum(.,3)`).</p><p>For my work, I need also to defined the derivatives of the polynomial matrices with respect to `X`or `Y`. Using the previous formulation, the derivatives can be easily obtained by subtracting 1 to the associated matrix `MX` or `MY` and by multiplying `C` by the right matrix `MX`or `MY`.</p><p>Currently this approach works fine for lower degrees but I need also to multiplying some polynomial matrices and this is the big problem of this approach. To deal with this problem I write manually the full matrix product (compute using Mathematica).</p><p>I want to extend my code for higher degrees and to manipulate more easily the polynomial matrices. So if you have any idea to do this.</p><p>I can use any toolbox in Matlab but at the end I need to have the matrices `MX`, `MY`, `E` and `C` (I need this separated matrices for doing some specific computations). I tried to use the `Symbolic Toolbox` but it seems to be very difficult to extract these four matrices when the polynomial matrix is complicated.</p><p>Example:</p><pre> H=[
1 0 Y/h 10*Y^2/h^2 5X*Y/h^2 0
0 1 -X/h X/h 50*X^2/h^2 60*X*Y/h^2
]</pre><pre> C=[
1 0 1 10 5 0
0 1 -1 1 50 60
]</pre><pre> E=[
0 0 1 2 2 0
0 1 1 1 2 2
]</pre><pre> MX=[
0 0 0 0 1 0
0 0 1 1 2 1
]</pre><pre> MY=[
0 0 1 2 1 0
0 0 0 0 0 1
]</pre><p>Problem: Compute `H*D'` and extract `C`, `E`, `MX` and `MY` (with `H` define above) and</p><pre> D=[
Y/h Y^2/h^2 X/h
X/h Y/h X*Y/h
]</pre>Luc/matlabcentral/answers/contributors/2705368-luctag:www.mathworks.com,2005:Question/1396452014-07-01T07:42:12Z2014-07-10T14:07:31ZHow to find position of a simulink blocks which are used in multiple sub-systems<p>Hi,</p><p>I want to find out relative position of a simulink block which is used in multiple sub-systems in a model.</p><p>P1 = get_param(blk1,'Position')
P2 = get_param(blk2,'Position')
P3 = get_param(blk3,'Position')
P4 = get_param(blk4,'Position')</p><p>gives me information about position in current sub-system. But I can not compare this information available in P1,P2,P3 and P4 as they are in different sub-systems.</p>Bhavin/matlabcentral/answers/contributors/4293839-bhavintag:www.mathworks.com,2005:Question/1398992014-07-02T13:01:44Z2014-07-10T14:06:24ZCode Generation GRT: Make DSM non-volatile<p>I have an model which is using DSM's to store information which is accessed by stateflow and the model. From this model I'm generating an exe using the GRT template, which is running in windows.</p><p>My question is whether there is a way of storing the state of each DSM so that if forms the initial value for the next execution of the exe; akin to non-volative storage on an embbed system</p>Matt/matlabcentral/answers/contributors/1143055-matttag:www.mathworks.com,2005:Question/1412692014-07-10T12:45:45Z2014-07-10T14:04:35ZAlgorithm for finding all possible combinations of integer numbers which their sum equals the target.<p>Hello,</p><p>I want to develop an algorithm which finds all the possible combinations to fill an area between 5 m^2 and 50 m^2 (integer), with blocks of size 1-10 m^2 (integer).</p><p>The rules are:</p><p>1.for every area we have option of choosing only 2 different blocks, one big one small.</p><p>2.if the big fills exactly the area we use one.</p><p>3.we are not allowed to use a number of smalls which their sum is >= big.</p><p>In order to understand better imagine that you want to put tiles in your kitchen, and you want the number and the type of each tile.</p><p>For ex. for 7 the combinations are:
(7)(6,1)(5,2)(5,1,1) (4,3)(4,1,1,1) (3,2,2) (3,1,1,1,1:this cant be used because you can put 3,3,1 instead.) (2,5: this you cant because you already chose 5,2) (1,3,3) (1,2,2,2).</p><p>Below I have my code which I do not know how to finalize.</p><p>Any help is much appreciated.</p><pre class="language-matlab">target = 7 ;
for i=10:-1:1
</pre><pre> if (i<=target)
if (i==target)
disp(['(',num2str(i),')'])
end
for j=1:1:10
if ((i+j)==target)
if (i>j) % in order to exclude double entries
disp(['(',num2str(i),',',num2str(j),')'])
% a = j/i;
% for l=1:1:a
% disp(['(',num2str(i),',',num2str(a),')'])
% end
else
for l=(j-1):-1:1</pre><pre> end
end
end
end
end
end</pre>Christos/matlabcentral/answers/contributors/5455014-christostag:www.mathworks.com,2005:Question/1342102014-06-14T03:39:10Z2014-07-10T14:03:36ZError message in support package installer in MATLAB R2014a<p>i am trying to install support package in MATLAB R2014a. when I'm selecting a package and clicking the next button it shows an error message : <b>The specified key is not present in this container.</b></p><img src = "/matlabcentral/answers/uploaded_files/14141/Capture.JPG"><p>How can i solve this problem. Plz help me.thanks in advance.</p>Syadus sefat/matlabcentral/answers/contributors/2725024-syadus-sefattag:www.mathworks.com,2005:Question/1412592014-07-10T11:02:12Z2014-07-10T14:03:30ZGraph Not Plotting All Values??<p>Hi,</p><p>I am trying to output a graph from my programme which will plot TSR against CP for values of TSR ranging from 4 to 10. This is my code:</p><pre class="language-matlab">filename = 'book2.xlsx';
Input = xlsread(filename);
N = xlsread(filename,'C7:C15')
r = xlsread(filename,'D7:D15')
C = xlsread(filename,'E7:E15')
S = xlsread(filename,'F7:F15')
Non = xlsread(filename,'G7:G15')
</pre><pre class="language-matlab">% Inputs
R=0.4; % Radius of Rotor
B=3; % Number of blades
V=2; % Fluid velocity
Rho=998; % Fluid Density
N=9; % Number of Blade Elements
Cp_estimate=0.5; % Estimate power coefficient
Alpha_design=4; % Design alpha
Cl_design=1.04; % Design lift coefficient
</pre><pre class="language-matlab">% Variables
TSR=4; % Initial tip speed ratio
Cp=0; % Initial power coefficient
i=1; % Counter
alpha_new=0; % Initial value for alpha new
axial_induction=0; % Initial axial induction factor
tolerance=0.01; % Tolerance Value
Check=1; % Initial check value
axial_induction_old=0; % Initial value for old axial induction factor
</pre><pre class="language-matlab">r_local=[(R./N)*1; (R./N)*2; (R./N)*3; (R./N)*4; (R./N)*5; (R./N)*6; (R./N)*7; (R./N)*8; (R./N)*9];
r_over_R=r_local./R;
TSR_local=r_over_R.*TSR;
</pre><pre class="language-matlab">Phi=(2/3)*atan(1./TSR_local);
C=((8.*pi.*r_local)./(B.*Cl_design)).*(1-cos(Phi));
sigma=(B*C)./(pi.*r_local.*2);
</pre><pre class="language-matlab">Cl=[1.3; 1.1; 1; 0.9; 0.86; 0.83; 0.8; 0.75; 0.5]; % Lift Coefficients
Cd=[0.027; 0.024; 0.02; 0.019; 0.018; 0.016; 0.013; 0.012; 0.01]; % Drag Coefficients
</pre><pre class="language-matlab">F=(2/pi).*acos(exp(-(((B/2).*(1-(r_over_R)))./((r_over_R).*sin(Phi)))));
</pre><pre class="language-matlab">axial_induction=1./(((4.*(sin(Phi).^2))./(sigma.*Cl_design.*cos(Phi)))+1);
angular_induction=(1-(3*axial_induction))./((4.*axial_induction)-1);
</pre><pre class="language-matlab">for TSR=4:10,disp(TSR), % TSR from 4 to 10
</pre><pre> while abs(Check)>=tolerance</pre><pre class="language-matlab">axial_induction_old=axial_induction;
TSR_local=TSR*(r_local./R); % Local Tip Speed Ratio
Phi=(2/3)*atan(1./TSR_local); % Angle of Relative Fluid
</pre><pre class="language-matlab">relative_wind=(1-axial_induction)./((1+axial_induction).*TSR);
</pre><pre class="language-matlab">F=(2/pi).*acos(exp(-(((B/2).*(1-(r_over_R)))./((r_over_R).*sin(relative_wind))))); % Tip Loss Factor
</pre><pre class="language-matlab">C_T=(sigma.*((1-axial_induction).^2).*((Cl.*cos(relative_wind))+(Cd.*sin(relative_wind))))./((sin(relative_wind)).^2);
</pre><pre class="language-matlab">if C_T(TSR,:)<0.96
axial_induction=1./(1+(4.*F.*(sin(relative_wind).^2))./(sigma.*Cl.*cos(relative_wind)));
else
axial_induction=1./(((4.*F.*cos(relative_wind))./(sigma.*Cl))-1);
end
</pre><pre class="language-matlab">D=(8./(TSR.*N)).*(F.*(sin(Phi).^2).*(cos(Phi)-((TSR_local).*(sin(Phi)))).*(sin(Phi)+((TSR_local).*(cos(Phi)))).*(1-(Cd./Cl).*atan(Phi)).*(TSR_local.^2));
Cp=sum(D);
</pre><pre class="language-matlab">Diff=axial_induction-axial_induction_old;
Check=max(Diff(:));
</pre><pre class="language-matlab">TSR=TSR+1;disp(TSR);
</pre><pre class="language-matlab">store_Phi(:,TSR)=Phi;
store_TSR_local(:,TSR)=TSR_local;
store_axial_induction(:,TSR)=axial_induction;
store_angular_induction(:,TSR)=angular_induction;
store_relative_wind(:,TSR)=relative_wind;
store_Check(:,TSR)=Check;
store_Diff(:,TSR)=Diff;
store_Cp(:,TSR)=Cp;
store_TSR(:,TSR)=TSR;
</pre><pre> end</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">figure(1)
plot(store_Cp,store_TSR)
hold all
title('Cp vs Tip Speed Ratio')
xlabel('TSR')
ylabel('Cp')
</pre><p>However, when I run the programme I get the following graph. It is clear that the programme is not plotting all TSR values. Could anybody please help with this?</p><img src = "/matlabcentral/answers/uploaded_files/15220/Graph.jpg">Kevin/matlabcentral/answers/contributors/5440375-kevintag:www.mathworks.com,2005:Question/1411582014-07-09T18:44:29Z2014-07-10T14:01:34ZIS THERE ANY TOOLBOX FOR K MEANS CLUSTERING IN MATLAB?<p>IS THERE ANY TOOLBOX FOR K MEANS CLUSTERING IN MATLAB?</p><p>PLS REPLY.ITS VERY URGENT</p>char S/matlabcentral/answers/contributors/5387480-char-stag:www.mathworks.com,2005:Question/1412772014-07-10T13:59:39Z2014-07-10T13:59:39ZMesh toolbox for matlab (Voronoi and non-convex polygon)<p>I am looking for a Matlab's toolbox for meshing a geometry. My question is very general because I want to mesh a geometry using voronoi decomposition or concave polygons.</p><p>For meshing my geometry using Voronoi decomposition, I have checked three solutions:</p><ul><li>matlab's functions but I want to obtain a clipped mesh and the matlab's tools didn't provide this kind of mesh</li><li><a href = "http://people.ee.ethz.ch/~mpt/3/">MPT3</a> but the definition of the mesh is difficult to use and I spend a very long time only for extract a correct definition of the geometry (right order of the vertices for each polygon...)</li><li><a href = "http://paulino.cee.illinois.edu/software.html">PolyMesher toolbox</a> which seems to work well (even with non-square geometry) but sometimes the geometry don't fit well the bounding-box and remains some troubles with my following computation (mechanical computation).</li></ul><p>If you have any idea of a simple toolbox (or simple code) for meshing simple geometry (without the <b>Mapping toolbox</b> ...).</p>Luc/matlabcentral/answers/contributors/2705368-luctag:www.mathworks.com,2005:Question/1412542014-07-10T10:21:18Z2014-07-10T13:55:52Zfitlm how to save predicted values?<p>Hey!
For further calculations I need to use my predicted values of my linear model.
Using fitlm I get e.g.
mdl =</p><p>Linear regression model:
MPG ~ 1 + Weight + Year + Weight^2</p><p>Estimated Coefficients:
Estimate SE tStat
<i>________</i> <i>________</i> <i>_____</i></p><pre> (Intercept) 54.206 4.7117 11.505
Weight -0.016404 0.0031249 -5.2493
Year_76 2.0887 0.71491 2.9215
Year_82 8.1864 0.81531 10.041
Weight^2 1.5573e-06 4.9454e-07 3.149</pre><pre> pValue
__________</pre><pre> (Intercept) 2.6648e-19
Weight 1.0283e-06
Year_76 0.0044137
Year_82 2.6364e-16
Weight^2 0.0022303</pre><p>Number of observations: 94, Error degrees of freedom: 89
Root Mean Squared Error: 2.78
R-squared: 0.885, Adjusted R-Squared 0.88
F-statistic vs. constant model: 172, p-value = 5.52e-41</p><p>Here I have 94 actual values, how can I get the predicted values of these?
E.g if I have 94 actual prices, how can i get the predicted prices through my model (best would be in an array).</p><p>Thanks a lot!</p>Tania/matlabcentral/answers/contributors/5140994-taniatag:www.mathworks.com,2005:Question/1399112014-07-02T14:33:50Z2014-07-10T13:55:34ZDLL issues with matdgns.c example<p>I trying to learn how .mat files manipulating functions works, so
I compiled matdgns.c but when I execute the file, it requires a lot
of DLL's, not just libmat.dll and libmx.dll. I used Visual Studio 2008 to compile the file. Is there some option that i need to change in VS to fix this ?</p>Michel/matlabcentral/answers/contributors/4904740-micheltag:www.mathworks.com,2005:Question/1252042014-04-10T02:57:31Z2014-07-10T13:51:48ZWhy DurationInSeconds doesn't work?<p>Hello,</p><p>We are trying to use PCI6602 Daqboard to generate a serial of pulses to control servo.
Our program is pretty simple like this:</p><p>s=daq.createSession('ni');</p><p>s.addCounterOutputChannel('Dev1','ctr0','PulseGeneration');</p><p>ch1=s.Channels(1);</p><p>for i=1:24</p><p>ch1.DutyCycle=0.08+0.006*(i-1);</p><p>s.DurationInSeconds=0.204;</p><p>s.startForeground();</p><p>end</p><p>It worked before. But these days, it seems like 's.DurationInSeconds' doesn't work. The signal generated by Daqboard is attached below. The duration time of signal sequence is much longer than 204 ms, which it suppose to be.</p><img src = "/matlabcentral/answers/uploaded_files/11194/Photo%20Apr%2009,%2010%2040%2050%20PM.jpg"><p>Anyone knows why?</p><p>Thanks</p>Jingyuan Dong/matlabcentral/answers/contributors/4652746-jingyuan-dongtag:www.mathworks.com,2005:Question/1398702014-07-02T09:55:21Z2014-07-10T13:50:37ZHow can I promote parameter from Serial Transmit block (Arduino) to a higher block in Simulink?<p>Hi all,</p><p>I'm working with 'Simulink Support Package for Arduino Hardware', with Serial Transmit block specifically, with an Arduino Mega 2560. I want to create a higher block that contains this block and others, so I'm trying to promote its parameter 'portNumber' (determine the serial port to use in Arduino) for change it in the higher mask.</p><p>When I create that mask, I add a new parameter and use the 'Promote underlying block parameter(s) to this mask parameter' button. All is ok until I press 'Build model'. The following error appears:</p><p>"Error evaluating 'InitFcn' callback of Arduino Serial Transmit block (mask)</p><p>Caused by: Undefined function or variable 'port'."</p><p>I don't know why it doesn't work, if anyone know what is happening and could help me I would appreciate. Thanks.</p>josemag/matlabcentral/answers/contributors/5273143-josemagtag:www.mathworks.com,2005:Question/1398402014-07-02T07:18:29Z2014-07-10T13:47:39Zis it possible to update the parameter of synchronous generator block in simulink through a matlab programme<p>is it possible to update the parameter of synchronous generator block in simulink through a matlab programme</p>nidhi pawar/matlabcentral/answers/contributors/5104333-nidhi-pawartag:www.mathworks.com,2005:Question/1398262014-07-02T05:20:12Z2014-07-10T13:45:52ZInclusion of custom ENUM file during code generation throwing error<p>Hi,</p><p>I am trying to include following header file containing ENUM definition during my Auto-code generation</p><p>typedef enum {
ENG_MOD_ENTRY_NON = 0
,ENG_MOD_ENTRY_OFF
,ENG_MOD_ENTRY_SLOWON
,ENG_MOD_ENTRY_ON
} ENG_MOD_ENTRY_ITMT;</p><p>But while code generation I am contineously getting the following error:</p><p>redeclaration of `ENG_MOD_ENTRY_NON ' previously declared at ..\l_TestIfDefine.h 21
redeclaration of `ENG_MOD_ENTRY_OFF' previously declared at ..\l_TestIfDefine.h 22
redeclaration of `ENG_MOD_ENTRY_SLOWON' previously declared at ..\l_TestIfDefine.h 23
redeclaration of `ENG_MOD_ENTRY_ON' previously declared at ..\l_TestIfDefine.h 24</p><p>How do I get rid of this error?</p>Aditya/matlabcentral/answers/contributors/3088645-adityatag:www.mathworks.com,2005:Question/1412752014-07-10T13:27:42Z2014-07-10T13:44:58ZIFFT and FFT user guide ?<p>Hi,</p><p>I am working now both with IFFT and FFT.</p><p>It is obvious that you need to know what are you doing, but I am wondering why in the help of Matlab there is so lack of information about how to proper use these functions: for example, regarding how to reorder the time and the frequency vectors after the transformations, about the scaling factor, and about the link between discrete and continuous transformations.</p><p>There is such a huge amount of different approaches on internet about how to use ifft and fft, and I can't believe that there is not an unique official guide on how to use these two functions, in different cases.</p><p>Maybe I was not able to look for the right one. Hope you can indicate me an official guide.</p><p>Best,</p><p>Maria</p>Maria/matlabcentral/answers/contributors/5027828-mariatag:www.mathworks.com,2005:Question/1347872014-06-17T02:18:32Z2014-07-10T13:43:35ZSimulink Sfunction Error - not a valid Win32 application<p>Since I have installed a Windows update I am getting the following error:
Error calling generated SFunction, XXXX_sfun. Invalid MEX-file 'H:\MATLAB\XXXX_sfun.mexw64': H:\MATLAB\XXXX_CTD_sfun.mexw64 is not a valid Win32 application.</p><p>If I remove one of the SFunctions from the model I no longer get the error. If I put that SFunction back into the model and remove a different SFunction from the model I no longer get the error.</p><p>There are no global variables.</p><p>The model worked before the Windows update. I have changed some formulas in the functions but nothing too significant. Running the Matlab code associated with the SFunctions by itself works fine, so I don't think it is a coding bug.</p><p>Not sure where to go from here.</p>Chris/matlabcentral/answers/contributors/2835427-christag:www.mathworks.com,2005:Question/1396982014-07-01T12:27:33Z2014-07-10T13:39:30ZSimulink Code Generation, independency from step-size and mat-logging<p>Hi everybody,</p><p>for a project I have to generate C Code from a Simulink-model, for me, what important is, the relationship between input and output, not the input and output. I mean they could be a constant or a sin wave, its not important, because I am going to use in another environment input=x , and output=2*x ... its so very simple. I am trying to generate a subsystem regarding to have this, which has just input/output and a Gain Block for multiplication.</p><p>The problem is ; I don't want neither Mat-Logging (actually any logging data)nor step-size ! I can disabled the mat-logging in config. but I cant configure the step size, if I set it as auto, it gets automatically 0.2s :/ How can I figure it out ? shortly I don't need to set a step-size , because this generated code should be called in main C-Script and should not be depended to value like 0.2s or 0.4s .Thanks in Advance...</p><p>Best Regards
Onur</p>Onur Isbecer/matlabcentral/answers/contributors/5345922-onur-isbecertag:www.mathworks.com,2005:Question/1412742014-07-10T13:22:19Z2014-07-10T13:37:26Zcalculating cdf with a matrix as an argument<p>I am trying to calculate the CDF, but want to calculate over a range, so I use a matrix as an argument, and get an error. Can someone point out what I'm doing incorrectly? Thanks.</p><p>-->mu = 1.5;</p><p>-->sigma = .11*mu
sigma =</p><pre> 0.165 </pre><p>delta =</p><pre> 0.
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.1
0.11
0.12
0.13
0.14
0.15
0.16
0.17
0.18
0.19
0.2
0.21
0.22
0.23
0.24
0.25
0.26
0.27
0.28
0.29
0.3
0.31
0.32
0.33
0.34
0.35
0.36
0.37
0.38
0.39
0.4
0.41
0.42
0.43
0.44
0.45
0.46
0.47
0.48
0.49
0.5
0.51
0.52
0.53
0.54
0.55
0.56
0.57
0.58
0.59
0.6
0.61
0.62
0.63
0.64
0.65
0.66
0.67
0.68
0.69
0.7
0.71
0.72
0.73
0.74
0.75
0.76
0.77
0.78
0.79
0.8
0.81
0.82
0.83
0.84
0.85
0.86
0.87
0.88
0.89
0.9
0.91
0.92
0.93
0.94
0.95
0.96
0.97
0.98
0.99
1.
1.01
1.02
1.03
1.04
1.05
1.06
1.07
1.08
1.09
1.1
1.11
1.12
1.13
1.14
1.15
1.16
1.17
1.18
1.19
1.2
1.21
1.22
1.23
1.24
1.25
1.26
1.27
1.28
1.29
1.3
1.31
1.32
1.33
1.34
1.35
1.36
1.37
1.38
1.39
1.4
1.41
1.42
1.43
1.44
1.45
1.46
1.47
1.48
1.49
1.5
1.51
1.52
1.53
1.54
1.55
1.56
1.57
1.58
1.59
1.6
1.61
1.62
1.63
1.64
1.65
1.66
1.67
1.68
1.69
1.7
1.71
1.72
1.73
1.74
1.75
1.76
1.77
1.78
1.79
1.8
1.81
1.82
1.83
1.84
1.85
1.86
1.87
1.88
1.89
1.9
1.91
1.92
1.93
1.94
1.95
1.96
1.97
1.98
1.99
2. </pre><p>-->cdf = .5[1+erf((delta-mu)/(sqrt(2*sigma^2)))]
!--error 276
Missing operator, comma, or semicolon.</p>Peter/matlabcentral/answers/contributors/4617450-petertag:www.mathworks.com,2005:Question/259462012-01-12T15:48:31Z2014-07-10T13:34:27ZArrays and embedded MATLAB function in Simulink<p>Dear all,</p><p>I am using Simulink (Matlab R2010a) to simulate the behaviour of an energy system. In this system, m boxes are connected in parallel and can be disconnected with a switch. The number of boxes m is a mask parameter which is defined by the user at the beginning of the simulation. Inputs of my embedded MATLAB function are the number of boxes m, the inlet power P[1,m] and the temperature T[1,m] of each box. Calculated parameters (outputs) are the produced gas flow rate G[1,m] and the temperature variation dT[1,m] of each box. The output dT[1,m] is connected with an integrator, which is connected with the input T[1,m].</p><p>This is the code structure in the embedded MATLAB function:</p><pre> function [G,dT] = Boxes(m,P,T)
G=zeros(1,m);
dT=zeros(1,m);
for i=1:
Pin=P(1,i);
Tout=T(1,i);
Gas=f(Pin,Tout);
dTout=h(Pin,Tout);
G(1,i)=Gas;
dT(1,i)=dTout;
end
end</pre><p>This code works in Matlab, but the simulation does not work in Simulink. I get the following error message:</p><pre> Data 'dT' (#146) is inferred as a variable size matrix, while its specified type is something else. </pre><p>In other words, I should specify in the "Ports and Data Manager" that the parameters P, T, G and dT are variable size matrix. But this would be wrong because the size of these arrays actually does not change during the simulation!</p><p>Another point: If I do so and specify that they are variable size matrix, I get the following error messages:</p><pre> Simulink cannot propagate the dimension mode from the output port 1 of 'Boxes/Bus Creator' to the input port 1 of 'Boxes/Memory'. One of the multiplexed signals at the output of the source has variable-size mode. This multiplexed signal has to be demultiplexed before Simulink can propagate it to the destination.</pre><p>and</p><pre> Output 'dT' (#166) has variable size but the upper bound is not specified; explicit upper bound must be provided.</pre><p>So I cannot use the Memory block with a variable size matrix and I have to explicit the upper bound of each variable size parameter.</p><p>Maybe I should explicit that these arrays are fixed size matrix, but I don’t know how.</p><p>Many thanks in advance for your help!</p><p>Floriane</p>Floriane/matlabcentral/answers/contributors/3261406-florianetag:www.mathworks.com,2005:Question/1411122014-07-09T14:03:20Z2014-07-10T13:31:47ZFor Loop Not Working??<p>Hi,</p><p>I am designing a programme which will operate using a for loop starting at a value of 4 and ending at 10 as shown in the code below:</p><p>for TSR=4:10;</p><p>I am unsure as to whether I should put the following line of code in the end of my program:</p><p>TSR=TSR+i;</p><p>I have also secified that i is a counting index of 1. If I dont put it in, the loop seems to keep interating for a TSR value of 4. But if I do put it in the for loop surpasses the final value of 10 and increases continuously. Could anybody please help with this problem?</p><p>Thanks,
Kevin</p>Kevin/matlabcentral/answers/contributors/5440375-kevintag:www.mathworks.com,2005:Question/1395092014-06-30T13:25:55Z2014-07-10T13:29:09ZProblem in code generated for variant subsystem<p>Hello All.
I need help for an issue regarding variant subsystem.</p><p>I am using Matlab R2011b.</p><p>My model has a variant subsystem which have two implementation subsystems. Each implementation include Stateflow chart.
Now problem is this, there is a separate function generated for chart in variant A , which is not used for variant B.</p><p>But this function is not guarded by preprocessor.</p><p>Something like this</p><pre class="language-matlab">static void enter_internal_ChartA_StateXYZ(void)
{
/* Some code for variant A chart*/
bla...
bla...
}
</pre><pre class="language-matlab">void mymodel_step(void)
{
#if VAR_A
bla......
bla......
enter_internal_ChartA_StateXYZ();
bla......
#elif VAR_B
bla......
bla......
bla......
#endif
}
</pre><p>Function enter_internal_ChartA_StateXYZ is used for VAR_A only but it is not
gaurded by preprocessor. So while compiling code for VAR_B, I am getting error.
Am I doing something wrong or is it Matlab bug ?</p><p>The only special thing I am using is <b>AUTOSAR target production package</b> target for code generation which is inherited from <b>ert target</b> only.</p>TAB/matlabcentral/answers/contributors/2299743-tabtag:www.mathworks.com,2005:Question/1411482014-07-09T17:55:02Z2014-07-10T13:28:32ZAdd trendline and calculate slope of trendline <p>Hi,</p><p>I have a set of X and Y data. I plotted a scatter plot for these 2 sets. I would like to add a trendline for the scatter plot and calculate the slope of this trendline while forcing the intercept to = 0. Basically this can be done in excel, but I would like to add this into my code and automate the process. Is this possible? I intend to use values from the trendline equation for other calculations. I have been looking at commands such as polyfit, but I am not sure this is the correct route</p><p>Thanks</p>Brian/matlabcentral/answers/contributors/4405932-briantag:www.mathworks.com,2005:Question/1409742014-07-08T17:38:14Z2014-07-10T13:27:47ZConnecting to Oracle express<p>I am having troubles connecting to oracle express db. When i am trying to connect to the database i get the following error:</p><pre class="language-matlab">>> conn = database('test_db','','zxcv','Vendor','Oracle',...
'DriverType','oci','Server','remotehost','PortNumber',
1234)
Error using database (line 309)
Java exception occurred:
java.lang.UnsatisfiedLinkError: no ocijdbc11 in
java.library.path
</pre>Paul/matlabcentral/answers/contributors/4714160-paul