https://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-04-26T13:28:33Ztag:www.mathworks.com,2005:Question/2136242015-04-26T13:18:34Z2015-04-26T13:28:33ZGetting the Polynomial coefficients<p>Hello,</p><p>I am trying to identify if a given function is polynomial or not and if it is polynomial what the coefficients are. For example;</p><pre class="language-matlab">sym F x
F= 5*x^5+cos(x)*x^2+1 % This is not polynomial because of cos(x) and I want to identify that.
[c,t] = coeffs(F);
PolyCoef = sym2poly(F);
</pre><pre class="language-matlab">c =
</pre><pre class="language-matlab">[ 5, 1, 1] % no cos(x) is given in here
</pre><pre class="language-matlab">>> t
</pre><pre class="language-matlab">t =
</pre><pre class="language-matlab">[ [x^5, 1], [x^2, x], [1, 1]] % no cos (x) is given in here
</pre><p>and sym2poly will give error. I am okay with the error as long as it does not stop the program and tell me that input function is not polynomial.</p><p>Thanks for the help.</p>Kamuranhttps://www.mathworks.com/matlabcentral/profile/authors/1504443-kamurantag:www.mathworks.com,2005:Question/2136192015-04-26T12:16:12Z2015-04-26T13:28:30Zi want to mark the highest point of any non-black pixel within the image to find the max point. <p>here is my image. I had ask before at https://www.mathworks.com/matlabcentral/answers/213198-i-want-to-mark-only-the-highest-middle-point-of-binary-image-but-it-show-the-min-point-too
but i might ask in not clear question.</p><p><<</p><img src = "/matlabcentral/answers/uploaded_files/29800/ggggggggg.PNG"><p>the last of my output will be like this.</p><img src = "/matlabcentral/answers/uploaded_files/29799/kkkkkkkkkkkk.PNG"><p>>></p>Nurul Najmahhttps://www.mathworks.com/matlabcentral/profile/authors/6323109-nurul-najmahtag:www.mathworks.com,2005:Question/2136062015-04-26T10:19:13Z2015-04-26T13:25:17ZNot enough input arguments.<p>I have a file called F.m which contains the following code:</p><pre class="language-matlab">1 % INPUT:
2 % 3D vector x
3 %
4 % OUTPUT:
5 % function value at x
6
7 function val = f(x)
8 val= x(1)^2 + x(1)*x(2)^3 - 12*x(3) + 4;
9 end
</pre><p>I am trying to call F.m in an algorithm in another file, but when I run the code, I get the following error:</p><p>"Error using F (line 8)
Not enough input arguments."</p><p>I'm new to MATLAB, so I'm not sure what I'm doing wrong here. Any help would be greatly appreciated!</p>Anonymous Chupacabrahttps://www.mathworks.com/matlabcentral/profile/authors/6458607-anonymous-chupacabratag:www.mathworks.com,2005:Question/2135442015-04-25T15:20:00Z2015-04-26T13:23:07ZHow do I overlay multiple logistic population curves on a single plot?<p>Firstly here is the code I have made to plot a logistic population curve:</p><pre class="language-matlab">% Run logistic dynamics for N generations and plot result
R= 1.6; % goodness/growth parameter
R2 = 0.8
R3 = 9
R4 = 1
n=25; % number of generations
x=[]; % initialise empty list of population values
x(1) = 0.001; % initial population
</pre><pre class="language-matlab">for t = 1:n-1
x(t+1) = R*x(t)*(1-x(t)); % logistic dynamics
end
figure(1); clf
plot(x,'b');hold on;
plot(x,'go');hold off;
axis([1 n 0 0.45]);
</pre><pre class="language-matlab">title('Example of Logistic Population Dynamics')
xlabel('Generation number');
ylabel('Population (fraction of max)');
grid on;
</pre><p>Now, i want to vary some factors to see what effect they have on population growth. However, I do not want them on separate plots so could someone explain to me how i can edit my code so i can have multiple logistic population curves on a single plot?</p><p>Kind regards and many thanks</p>Jack Farrhttps://www.mathworks.com/matlabcentral/profile/authors/6456760-jack-farrtag:www.mathworks.com,2005:Question/2136232015-04-26T13:15:34Z2015-04-26T13:15:34Zpoor performance by neural network <p>I started doing Devangiri character recognition .. I had handwritten 50 Devanagiri characters by 5 persons..I finished the feature extraction portion .. My features for each image in having 1 coloumn and 55 rows.
My feature vectors are arranged like coloumn 1 contains letter 1 feature by writer 1, coloumn 2 contains letter 2 feature by writer 2 . . . . . letter 50 by writer 5.</p><p>For training i am taking first 4 writers characters . So the training matrix named PP has 55 rows and 200 coloumns .. My target I have declared as</p><pre class="language-matlab">Target=[eye(50) eye(50) eye(50) eye(50) ]
</pre><p>Now seeing tutorials i started training the network as below</p><pre class="language-matlab">hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);
net = configure(net,P,T);
net=init(net);
[net,tr] = train(net,P,T);
</pre><p>After doing it I am getting very poor performance =0.018.. On testing the test set PP(:,201:250) i am not getting any proper result.. Am i doing the training wrong .. I am a beginner just started on neural networks .. Thanking you</p>madhusudan kumarhttps://www.mathworks.com/matlabcentral/profile/authors/6288960-madhusudan-kumartag:www.mathworks.com,2005:Question/2136212015-04-26T12:36:53Z2015-04-26T13:13:24Zhow to took the no every iteration<pre> for i=1:6
mn=a{i};
end </pre><img src = "/matlabcentral/answers/uploaded_files/29801/1.JPG"><p>now i wish to take first value from mn when i=1 and then second value so on till mn value end in iteration i=1
and now iteration i=2 take first variable from second time run mn values and so on till iteration i=6 .if mn has no value then jump to second iteration.</p>singhhttps://www.mathworks.com/matlabcentral/profile/authors/6334127-singhtag:www.mathworks.com,2005:Question/2133402015-04-24T07:33:30Z2015-04-26T13:12:06Zwhy getting inseasible solutions using fmincon?<p>Hi
I have a optimization problem with many optimization variables (~600). Amongst them, only 77 variables directly participate in the objective function. These 77 variables are used in linear constraints of the problem as well. The other variables only participate in nonlinear equality constraints of the problem and not the objective function.
I codded the problem with <b>fmincon</b> and it gives the exit flag -2, which means there is no feasible solution.</p><p>On the other hand, When I ignore the nonlinear equality constraints and only consider the linear constraints, the problem leads to a feasible solution.</p><p>For this reason, I was thinking the problem might be for the nonlinear equality constraints. So, I tried to consider these nonlinear equality constraints as a nonlinear system and solved it with 'fsolve' for the same initial guess. <b>fsolve</b> leads to an acceptable answer for this system, as its fval values where almost 0. So, the non linear equality constraint(system) have a feasible answer.
I also, supplied the solution of <b>fsolve</b> as initial guess for <b>fmincon</b> but it didn't work too.</p><p>So based on above, what is the problem with using <b>fmincon</b> (or me) and getting infeasible solution?</p><p>I attached 2 zipped file here. One is for solving the problem in fmincon and the other is about solving the nonlinear constraint with <b>fsolve</b> to be sure that the solution is feasible. Please take a look at them if you have time.</p><p>Your help and suggestions are much appreciated.</p>Jamais avenirhttps://www.mathworks.com/matlabcentral/profile/authors/4439075-jamais-avenirtag:www.mathworks.com,2005:Question/2135702015-04-25T21:00:45Z2015-04-26T13:10:58Zexist a mobile phone app for tha lumia 930<p>Dear all,</p><p>I want to know if there exists a mobile app for the nokia lumia 930.
If yes, were can I get it?
If no, why and will you develop one?</p><p>Thank you in advance for you answer.</p><p>Kind regards
Daniela</p>Daniela Miebachhttps://www.mathworks.com/matlabcentral/profile/authors/5211681-daniela-miebachtag:www.mathworks.com,2005:Question/2133762015-04-24T11:47:52Z2015-04-26T13:09:49ZHow do you fit a curve through 3D points, using splines, constrained within a volume.<p>Suppose I have an array of points in 3space,</p><pre class="language-matlab">[r1; r2; ... ; rn]
</pre><p>where</p><pre class="language-matlab">ri = [xi yi zi]
</pre><p>are it's coordinates. I want to fit a curve (a spline) in 3 dimensions between these points. However, I want the interpolated curve between points ri and rj to be constrained within a certain volume. How could I go about doing this?</p><p>EDIT: To elaborate, each pair of points exist on distinct faces of a shared tetrahedral. The interpolated curve between said points has to stay within this tetrahedral.</p>Laurence hutton-smithhttps://www.mathworks.com/matlabcentral/profile/authors/2590267-laurence-hutton-smithtag:www.mathworks.com,2005:Question/2132762015-04-23T23:41:37Z2015-04-26T13:08:13ZCan anyone help with this C++ code?<p>Hello everyone, I’m having difficulties with importing the data from a text file into an array. It is not working with the file that contains negative values. It is only working with the file that contains positive values. Any help or suggestions would be greatly appreciated. I've attached the text files containing the data and the C++ code. Thank you all for your time in advance.</p>Jhttps://www.mathworks.com/matlabcentral/profile/authors/6153505-jtag:www.mathworks.com,2005:Question/2136152015-04-26T11:16:47Z2015-04-26T13:08:12Zhow we change a audio signal amplitude value to frequency value?<p>how can we convert amplitude to frequency?</p>parthasarathi ghoraihttps://www.mathworks.com/matlabcentral/profile/authors/6423549-parthasarathi-ghoraitag:www.mathworks.com,2005:Question/1832872015-03-15T17:54:44Z2015-04-26T13:04:57Zdicominfo command ".dcm not found"<p>I am trying to read some dicom images in .dcm extension .. Following codes i used..
I dont know what is the problem.. Till yesterday same codes worke fine</p><pre class="language-matlab">[name, pathname] = uigetfile('*.dcm', 'Select a reference DICOM file...') ;
info=dicominfo(name); % obtain the information of the dicom
Y = dicomread(info);
figure,imshow(uint8(Y)),
</pre><p>Once i am selecting an image i am getting following error</p><pre class="language-matlab">Error using dicominfo>getFileDetails (line 390)
File "dess_060.dcm" not found.
</pre><pre class="language-matlab">Error in dicominfo (line 36)
fileDetails = getFileDetails(filename);
</pre><pre class="language-matlab">Error in main_code1 (line 18)
info=dicominfo(name)
</pre>madhusudan kumarhttps://www.mathworks.com/matlabcentral/profile/authors/6288960-madhusudan-kumartag:www.mathworks.com,2005:Question/2136102015-04-26T10:42:02Z2015-04-26T12:59:14ZHow to use matlab to find unknowns in nonlinear equation at a certain readings<p>Hello everybody.</p><p>Assume I have the following equation: Y = a0 + a1*log(x1) + a2*log(x2) + a3*x3 + e. The unknowns here are a0, a1, a2 and a3. I need to find the values of these unknowns in order to minimize the value of error, e. Note that I have a matrix of readings such as: data = [0 5 10 15 20;1 2 3 4 5;6 7 8 9 10;11 12 13 14 15], where x1=data(1), x2=data(2), x3=data(3), and y=data(4).
How can I find these unknowns using MATLAB and how can I decide that these values of unknowns are best fit or not.</p>Ibrahim Alnahhalhttps://www.mathworks.com/matlabcentral/profile/authors/6368829-ibrahim-alnahhaltag:www.mathworks.com,2005:Question/2136202015-04-26T12:19:01Z2015-04-26T12:59:05Zproblem while converting day and month to day number<p>Sir,</p><p>How to convert day and month to day number I tried this,</p><pre> daynum(p,1)=daynum1(day,mon); </pre><p>but it shows error while running.Is this correct or any other options are available? please help me to move forward</p><p>Thank you</p>jisha rhttps://www.mathworks.com/matlabcentral/profile/authors/6458832-jisha-rtag:www.mathworks.com,2005:Question/2135882015-04-26T03:41:48Z2015-04-26T12:58:12ZCan I lump my constraints so as to avoid adding unnecessary optimization variables <p>I have an optimization problem with numerous decision variables. Among them, a small portion of them participates in objective functions and some constraints. Other optimization variables participate in other constraints (most of them). As performance of <b>fmincon</b> may depends on number of decision variables, Can I lump some constraint in order to avoid adding unnecessary decision variables?
For example:
I have the following constraints (it's part of them). <b>pgn,pdn,v_mt,Delta,pg,pd</b> are optimization variables.</p><pre> % First we define the new variables for the sake of
%readability of the scrips (I write only some of them here...):
pgn = X( 145:183 )';
pdn = X( 184:222 )';
pg = X( 301:310 )';
pd = X( 321:339 )';
...
pbal_eq = -(pgn-pdn)+v_mt.*((Ybus_m.*cos(Delta))*v_mt);% pgn:39/pdn:39/v_m:39/v_a=39 (39 eq)</pre><pre class="language-matlab">pgn_eq = - pgn + [zeros(29,1);pg]; (39 eq)
</pre><pre class="language-matlab">pdn_eq= -pdn+[0;0;pd(1);pd(2);0;0;pd(3);pd(4);0;0;0;pd(5);0;0;pd(6);pd(7);0;pd(8);0;pd(9);...
pd(10);0;pd(11);pd(12);pd(13);pd(14);pd(15);pd(16);pd(17);0;pd(18);0;0;0;0;0;0;0;pd(19)];%(39eq)
</pre><pre class="language-matlab">Ceq=[pbal_eq;pgn_eq;pdn_eq]
</pre><p>Can I lump it this way and avoid having unnecessary optimization variables? So decision variables , pgn,pdn are neglected and only <b>v_mt,Delta,pg,pd</b> are kept.</p><pre class="language-matlab">pgn=[zeros(29,1);pg]; %
</pre><pre class="language-matlab">pdn= [0;0;pd(1);pd(2);0;0;pd(3);pd(4);0;0;0;pd(5);0;0;pd(6);pd(7);0;pd(8);0;pd(9);...
pd(10);0;pd(11);pd(12);pd(13);pd(14);pd(15);pd(16);pd(17);0;pd(18);0;0;0;0;0;0;0;pd(19)];%(39eq)
</pre><pre class="language-matlab">pbal_eq = -(pgn-pdn)+v_mt.*((Ybus_m.*cos(Delta))*v_mt);% pgn:39/pdn:39/v_m:39/v_a=39 (39 eq)
</pre><pre class="language-matlab">Ceq=[pbal_eq];
</pre><p>I know that constraints <b>pgn_eq</b> and <b>pdn_eq</b> are linear, so I should apply them with <b>Aeq , Beq</b> matrices. But I am writing it this way to get the gist of lumping the constraints. How ever, it doesnt change the fact, because I can still lump them in <b>Aeq , Beq</b> too if the idea of lumping the constraints is correct. Moreover, if lumping is possible, so I dont need to define linear constraints in <b>Aeq,Beq</b> for <b>pgn , pdn</b>. In that case, I only have one nonlinear equality constraint <b>(pbal_eq)</b>. (if we assume these as the whole constraints I have)</p>Jamais avenirhttps://www.mathworks.com/matlabcentral/profile/authors/4439075-jamais-avenirtag:www.mathworks.com,2005:Question/2135632015-04-25T19:37:29Z2015-04-26T12:18:18ZDeclaring variables with high precision<p>Hi</p><p>I have the following piece of code that I have also implemented in Fortran. According to Fortran the variable <b>Ax(3,6,4)</b> should yield a value of 1e-24, however, in the Matlab-code below the variable <b>Ax(3,6,4)</b> gets a value of 0. I believe it is because I lose precision "along the way" when declaring variables and performing calculations.</p><p>Question: Is there a way to define the relevant variables such that they retain their precision?</p><pre class="language-matlab">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CONSTANTS
clc
clear all
</pre><pre class="language-matlab">sym_weight = [4/9, 1/9,1/9,1/9,1/9, 1/36,1/36,1/36,1/36];
</pre><pre class="language-matlab">dir_x = [ 0, 1, 0, -1, 0, 1, -1, -1, 1];
dir_y = [ 0, 0, 1, 0, -1, 1, 1, -1, -1];
</pre><pre class="language-matlab">ly = 11; lx = ly;
xC = 5; yC=xC;
</pre><pre class="language-matlab">density_high = 1.0;
density_low = 0.1;
radius = 2;
interface_w = 1;
sigma_st = 0.0001;
</pre><pre class="language-matlab">beta = 12*sigma_st/(interface_w*(density_high-density_low)^4);
kappa = 1.5*sigma_st*interface_w/(density_high-density_low)^2;
</pre><pre class="language-matlab">saturated_density = 0.5*(density_high+density_low);
for x=1:lx
for y=1:ly
for i=1:9
fIn(i, x, y) = sym_weight(i)*density_high;
gIn(i, x, y) = 3*sym_weight(i);
</pre><pre> test_radius = sqrt((x-xC)^2 + (y-yC)^2);
if(test_radius <= (radius+interface_w))
fIn(i, x, y) = sym_weight(i)*( saturated_density - 0.5*(density_high-density_low)*tanh(2*(radius-sqrt((x-xC)^2 + (y-yC)^2))/interface_w) );
end
end
end
end</pre><pre class="language-matlab">density_2d = ones(lx)*saturated_density;
for i=1:lx
density_aux(:,:,i) = abs(density_2d(:, i)');
end
</pre><pre class="language-matlab">density_local = sum(fIn);
L_density_local = (+1.0*(circshift(density_local(1,:,:), [0, +1, +1]) + circshift(density_local(1,:,:), [0, -1, +1]) + circshift(density_local(1,:,:), [0, +1, -1]) + circshift(density_local(1,:,:), [0, -1, -1])) + ...
+4.0*(circshift(density_local(1,:,:), [0, +1, +0]) + circshift(density_local(1,:,:), [0, -1, +0]) + circshift(density_local(1,:,:), [0, +0, +1]) + circshift(density_local(1,:,:), [0, +0, -1])) + ...
-20.0*density_local(1,:,:));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
</pre><pre> chem_pot = 4*beta*(density_local-density_low).*(density_local-density_high).*(density_local-density_aux) - kappa*L_density_local/6;</pre><pre class="language-matlab">i=3;
</pre><pre class="language-matlab">Ax(i,:,:) = (+circshift(chem_pot(1,:,:), [0,-2*dir_x(i),-2*dir_y(i)]) - chem_pot(1,:,:));
Ax(3,6,4)
</pre>Niles Martinsenhttps://www.mathworks.com/matlabcentral/profile/authors/2415956-niles-martinsentag:www.mathworks.com,2005:Question/2131352015-04-23T06:58:27Z2015-04-26T12:03:30Zhow to normalize the image please provide the code for it<p>to noramlize an image please provide the matlab code</p>himanshu sharmahttps://www.mathworks.com/matlabcentral/profile/authors/6447437-himanshu-sharmatag:www.mathworks.com,2005:Question/2135902015-04-26T04:54:22Z2015-04-26T11:58:14Zgetting some unknown error in 48 column plzz help<p>i have been running this code in my work but there is some thing wrong in 48 line</p><p>this is the error msg</p><p>Error: File: ArrayFactor.m Line: 48 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "ArrayFactor".)</p>sandy sanhttps://www.mathworks.com/matlabcentral/profile/authors/6458077-sandy-santag:www.mathworks.com,2005:Question/2136182015-04-26T11:57:34Z2015-04-26T11:57:34Zhow to delete any variable from outside the for loop<pre> N=20;
area=100;
X=rand(1,N)*area;
Y=rand(1,N)*area;
htext=[];
for i1=1:2
for i=1:N
htext(i)=text(X(i),Y(i),num2str(i),'fontsize',20);
hold on
end
end
for ii=1:5
delete(htext(ii));
end</pre><p>now error is come when delete(htext) is execute plz give me some solution.</p><p>beacuse it show the message when cursor move on the htext variable 'htext size will be change every iteration '.how to delete hetxt value in for loop and out of for loop.</p><img src = "/matlabcentral/answers/uploaded_files/29797/1.png">singhhttps://www.mathworks.com/matlabcentral/profile/authors/6334127-singhtag:www.mathworks.com,2005:Question/2136162015-04-26T11:48:05Z2015-04-26T11:55:11Zintlinprog in student version 2013a<p>I am currently trying to solve the traveling salesman problem in my math class project
here is an example : <a href = "http://www.mathworks.com/help/optim/ug/travelling-salesman-problem.html">http://www.mathworks.com/help/optim/ug/travelling-salesman-problem.html</a></p><p>but apparently I need this intlinprog(), is there any way to solve this problem without this function,
or get it for free ? or upgrade my old version to 2014 for free ?</p><p>Thanks in advance</p>Ayoub Makrozhttps://www.mathworks.com/matlabcentral/profile/authors/5622553-ayoub-makroztag:www.mathworks.com,2005:Question/2136172015-04-26T11:53:30Z2015-04-26T11:53:30Zwhy target data is only binary in the pattern recognition (nnstart) ??<ul><li><i>bold</i> *</li></ul>Omar Awadhttps://www.mathworks.com/matlabcentral/profile/authors/6373486-omar-awadtag:www.mathworks.com,2005:Question/2135812015-04-25T23:34:24Z2015-04-26T11:53:27ZHow do I get the least used character in the text file ?<pre> a= textread('GreatExpectations.txt','%c');
[m]=length(a);
most_used_letter=char(mode(0+a))</pre>Anthony Massadhttps://www.mathworks.com/matlabcentral/profile/authors/6062758-anthony-massadtag:www.mathworks.com,2005:Question/2134722015-04-25T03:47:18Z2015-04-26T11:53:23ZHow to programatically get the point of intersection between the unit circle and root locus<p>I know I can use <i>rlocfind</i> and roughly estimate the value of gain by picking the intersection on the plot but I was wondering if I could get the precise value for gain at the point where unit circle intersects with root locus.</p>Hasan Ghorbanihttps://www.mathworks.com/matlabcentral/profile/authors/6411542-hasan-ghorbanitag:www.mathworks.com,2005:Question/2135862015-04-26T02:23:33Z2015-04-26T11:44:35Zhow to use ode23 to solve 2nd order equation<p>the equation likes this b*y'/x-a*y^2=y'', dy/dx=y'' a and b are constants y(0)=10, y'(0)=1</p>picc olohttps://www.mathworks.com/matlabcentral/profile/authors/6457884-picc-olotag:www.mathworks.com,2005:Question/2135802015-04-25T23:19:25Z2015-04-26T11:41:46ZRunning mexw64 files in R2013a Student version<p>I have Matlab Student version R2013a, which responds "mexw32" to the "mexext" command (even though I'm running it over Windows 8.1 64 bit). Is it possible to run a "mexw64" file on this version of Matlab or should I update it to a different/newer one?</p>Solivan Valentehttps://www.mathworks.com/matlabcentral/profile/authors/4855786-solivan-valentetag:www.mathworks.com,2005:Question/2135102015-04-25T09:23:01Z2015-04-26T11:35:37Z Locate an installed software in Windows using MATLAB<p>Hi,</p><p>Is it possible to find the location of an installed software in Windows using MATLAB? I need my MATLAB code to find the location of an installed application (exe file) and then run it. I found this string in stackoverflow website:</p><pre class="language-matlab">notepadEdit = winqueryreg('HKEY_CLASSES_ROOT','Applications\notepad.exe\shell\edit\command')
</pre><p>but it doesn't work for an app that is installed in program files.</p><p>Thank you in advance for any hint.</p>Mehdihttps://www.mathworks.com/matlabcentral/profile/authors/2875994-mehditag:www.mathworks.com,2005:Question/2136092015-04-26T10:34:01Z2015-04-26T11:20:03ZAccess elements of a Vector without a few Indices?<p>Say suppose I have a vector</p><pre class="language-matlab">X = [4 5 1 7 3 9 2 4]
</pre><p>and I want to access X but without indices: 1, 4 and 6. I tried</p><pre class="language-matlab">X(~[1, 4, 6])
</pre><p>But that's not working. Any suggestions.</p><p>Thanks</p><p>PS: I don't want to modify the vector.</p>Pankajhttps://www.mathworks.com/matlabcentral/profile/authors/5953919-pankajtag:www.mathworks.com,2005:Question/2134522015-04-24T23:10:41Z2015-04-26T11:09:29ZSaving the output of a loop into a matrix or a vector <p>Hello,</p><p>I am trying to save the result of this loop into a matrix with the standard technique where I name a matrix in the loop. But it doesn't seem to be working here.</p><p>Note: matrixmax1diff, matrixmax2diff, matrixmax3diff are 4x2 matrices, and TTT1,2,3 are 4x2 matrices of variables with respect to which I would like to solve the system of "24" equations. Overall the solution to the system is given by 24 variables (x1_H1H2H3 , etc.).</p><p>Thank you,</p><p>here is my code:</p><pre class="language-matlab">for i=1:4
for j=1:2
S=solve(matrixmax2diff(i,j)==0 , matrixmax3diff(i,j)==0 , matrixmax3diff(i,j)==0 , TTT1(i,j) , TTT2(i,j) , TTT3(i,j) )
end
end
</pre><p>Output:</p><p>S =</p><pre> x1_H1H2H3: [1x1 sym]
x2_H1H2H3: [1x1 sym]
x3_H1H2H3: [1x1 sym]</pre><p>S =</p><pre> x1_L1H2H3: [1x1 sym]
x2_H1L2H3: [1x1 sym]
x3_H1H2L3: [1x1 sym]</pre><p>S =</p><pre> x1_H1H2L3: [1x1 sym]
x2_L1H2L3: [1x1 sym]
x3_H1L2H3: [1x1 sym]</pre><p>S =</p><pre> x1_L1H2L3: [1x1 sym]
x2_L1L2L3: [1x1 sym]
x3_H1L2L3: [1x1 sym]</pre><p>S =</p><pre> x1_H1L2H3: [1x1 sym]
x2_H1H2L3: [1x1 sym]
x3_L1H2H3: [1x1 sym]</pre><p>S =</p><pre> x1_L1L2H3: [1x1 sym]
x2_H1L2L3: [1x1 sym]
x3_L1H2L3: [1x1 sym]</pre><p>S =</p><pre> x1_H1L2L3: [1x1 sym]
x2_L1H2H3: [1x1 sym]
x3_L1L2H3: [1x1 sym]</pre><p>S =</p><pre> x1_L1L2L3: [1x1 sym]
x2_L1L2H3: [1x1 sym]
x3_L1L2L3: [1x1 sym]</pre>Shaden SHABAYEKhttps://www.mathworks.com/matlabcentral/profile/authors/6454212-shaden-shabayektag:www.mathworks.com,2005:Question/2136132015-04-26T11:01:50Z2015-04-26T11:03:08ZHow do i create GUI using projectile motion? The GUI is required to be able to input value of x0,y0,v0x,v0y and also able able user to press'redraw plot' button to update figure for projectile motion<pre class="language-matlab">x0=0;
y0=10;
v0=5;
angle0=(pi/3);
v0x= v0*cos(pi*(angle0/180));
v0y= v0*sin(pi*(angle0/180));
g=9.81;
</pre><pre class="language-matlab">time = calc_time(g,v0y,y0)
range= calc_range(v0x,time)
v_final=calc_v_final(v0x,v0y)
</pre><pre class="language-matlab">t=linspace(0,time,100);
x=x0+ v0*cos(angle0)*t;
y=y0+ v0*sin(angle0)*t - g*t.^2/2;
plot(x,y)
xlabel('x-direction displacement');
ylabel('y-direction displacement');
title ('Projectile Motion')
</pre>Yeap Jia Weihttps://www.mathworks.com/matlabcentral/profile/authors/6267542-yeap-jia-weitag:www.mathworks.com,2005:Question/2136122015-04-26T10:59:45Z2015-04-26T11:00:14ZSave data to text file. Two vectors, a konstant and a text<p>Hello everyone!</p><p>I am trying to save some data to a .txt file, and i am having a bit of a trouble for it to save correct.</p><p>i have the following code:</p><pre class="language-matlab">P';
F';
</pre><pre class="language-matlab">fprintf(fid, [ header1 ' ' header2 ' ' header3 ' ' header4 '\r\n']);
fprintf(fid, '%f %f %f %f \r\n', [P F L S]');
fclose(fid);
</pre><p>P and F is a vector of 1xn length, while L and S only has one value.</p><p>I need it to save it to a .txt file, that i can read again. Havn't got to the load part yet, since i want the file to save this data correct.</p><p>Something like this:</p><pre class="language-matlab">F P L S
1 1 5 text
2 2
3 3
</pre><p>any ideas what would make this work?</p><p>Thanks in advance :)</p>Kasper Jørgensenhttps://www.mathworks.com/matlabcentral/profile/authors/6354174-kasper-jorgensentag:www.mathworks.com,2005:Question/2136112015-04-26T10:52:31Z2015-04-26T10:52:31ZWhat is the licence agreement? <p>I am about to graduate with in a year from my college, and the college does used a lot of Matlab, in turn so do i. I will plan on using this software for future use on my home computer. I was wondering what are the differences between the HOME and student versions of Matlab. For example in the student version do i get all of the commands for the toolbox or it just a partial limit on the toolbox commands, what do i get with the Home version vs the student version toolboxes.
Also, i was wondering do the price for the student and the home version are annual fees for the software?
For example Student verison is $100 do i have to pay for this ever year just to get the license to use the software?</p>Ethan Millerhttps://www.mathworks.com/matlabcentral/profile/authors/6428566-ethan-millertag:www.mathworks.com,2005:Question/2136022015-04-26T08:19:01Z2015-04-26T10:32:15ZCreate another pushbutton and/or textbox after pressing a pushbutton<p>Hello I'm Brilly.
I'm new to Matlab GUI.</p><p>I'm not using GUIDE.
My question is about this :</p><p>I created 1 textbox as an input box (integer) and 1 pushbutton
that acts as an "OK" button.</p><p>What I want is when user input a number n and press the "OK",
then n textboxes + 1 pushbutton (another "OK" button) will appear.</p><p>I don't understand the PDF given here about GUI, so I searched in youtube
and learnt that I need to use something like this when creating the first "OK" button after the first textbox ("parameter"):</p><p>var=uicontrol('style','pushbutton','string','OK',{@fun,parameter});</p><p>and then I must somehow use the function "fun" to create the n textboxes and another "OK" pushbutton.</p><p>I did it. But then I couldn't further use the n textboxes as input boxes.</p><p>I also wanted to take the integer in "parameter" but couldn't do that.</p><p>Was I making mistake in creating the "fun" function?
It seems like a simple problem but I'm new so can't do much.
Hope anybody can help.
Thank you very much.</p>Brilly Salindehohttps://www.mathworks.com/matlabcentral/profile/authors/6163428-brilly-salindehotag:www.mathworks.com,2005:Question/2136042015-04-26T08:48:08Z2015-04-26T10:27:58ZCan I scan 10 arrays all together to find one smallest value between all arrays?<p>I have 10 arrays.I need to be able to find the smallest value. I want to find another way of doing this rather than combining all 10 arrays into 1 and then scanning them.</p>MEhttps://www.mathworks.com/matlabcentral/profile/authors/5945733-metag:www.mathworks.com,2005:Question/2136082015-04-26T10:27:52Z2015-04-26T10:27:52ZI am getting this error "Undefined function 'assignDetectionsToTracks' for input arguments of type 'double'." . So is the function not there in CV toolbox 5.0? If so what is a similar function available that I can use<p>I'm trying to use this function from multiple objects tracking code in MATLAB, but I'm having trouble since it depends on assignDetectionsToTracks function which I cannot find in my toolbox</p><p>function [assignments, unassignedTracks, unassignedDetections] = ...
detectionToTrackAssignment()</p><pre> nTracks = length(tracks);
nDetections = size(centroids, 1);</pre><pre> % Compute the cost of assigning each detection to each track.
cost = zeros(nTracks, nDetections);
for i = 1:nTracks
cost(i, :) = distance(tracks(i).kalmanFilter, centroids);
end</pre><pre> % Solve the assignment problem.
costOfNonAssignment = 20;
[assignments, unassignedTracks, unassignedDetections] = ...
assignDetectionsToTracks(cost, costOfNonAssignment);
end</pre>Jyotsna Tripathihttps://www.mathworks.com/matlabcentral/profile/authors/6109992-jyotsna-tripathitag:www.mathworks.com,2005:Question/2136072015-04-26T10:27:37Z2015-04-26T10:30:51Zhow to convert this image to the original one?<img src = "/matlabcentral/answers/uploaded_files/29795/mm.png"><img src = "/matlabcentral/answers/uploaded_files/29796/lena_2.bmp"><pre class="language-matlab"><</matlabcentral/answers/uploaded_files/29793/lena_2.bmp>>
</pre><pre class="language-matlab">I am using
imshow(filename)
</pre><pre class="language-matlab">I also used map and ind2rgb, but these two are also not helping me to get back the original image(image 2).
Need your help...help me.
</pre>tina jainhttps://www.mathworks.com/matlabcentral/profile/authors/5644128-tina-jaintag:www.mathworks.com,2005:Question/2136052015-04-26T09:15:27Z2015-04-26T10:13:38Zvertical alignment with different size character with fprintf.<pre class="language-matlab">C = {'p.1001',100.500,250.350,;'102',110.550,255.220;'m285',115.210,266.333};
fileID = fopen('celldata.dat','w');
formatSpec = '%s %15.3f %15.3f\n';
[nrows,ncols] = size(C);
for row = 1:nrows
fprintf(fileID,formatSpec,C{row,:});
end
fclose(fileID);
</pre><p>% in this case second and third columns cannot be vertically aligned in the text file because first columns' characters are different size. When I use tab (/t), the situation is still same. Is there any way to vertically align 2rd and 3rd columns as independently the 1st columns' characters size?</p>sermethttps://www.mathworks.com/matlabcentral/profile/authors/3951076-sermettag:www.mathworks.com,2005:Question/2136012015-04-26T07:16:29Z2015-04-26T09:52:40Zcode for matrix conversion<p>How can we convert any matrix into phase variable form..</p>Nitheesh Mhttps://www.mathworks.com/matlabcentral/profile/authors/6455372-nitheesh-mtag:www.mathworks.com,2005:Question/2136002015-04-26T07:08:25Z2015-04-26T09:45:07Zneural network how to orgnize the data<p>I have a problem with nn classification ,I have 19 different classes , each class has 20 features and each feature has 200 samples(it could be more in future), how should I orgnize the input matrix ?
is it 20 x (200*19) or (20 *19) x 200 , and the target 1 x (200 * 19) is that right ? or should I use eye() as I read in some answers?
another question is how to decide the most appropirate number of hidden layers(middle layers not input and output) and number of nerouns in each layer ?
the last thing .. neural network provide different results each run .. is it possible to save the best run net configration and use it later to provide the same or approximated results ??</p><p>thanks in advance</p>Lama AlDeenhttps://www.mathworks.com/matlabcentral/profile/authors/5334716-lama-aldeentag:www.mathworks.com,2005:Question/2135402015-04-25T14:08:29Z2015-04-26T08:59:09ZHow can I merge two surfaces?<p>Hi to everyone,</p><p>I have to surfaces (created with hold on/off), but I need them to as one surface, to merge them and than that surface combine with one ellipse to become one ruled surface.</p><p>I hope my question is clear.. how can I merge two surface, create them as one without using hold on/off?</p><p>Thank you</p>Besim Helichttps://www.mathworks.com/matlabcentral/profile/authors/6444731-besim-helictag:www.mathworks.com,2005:Question/2131982015-04-23T14:17:18Z2015-04-26T08:53:15Zi want to mark only the highest middle point of binary image but it show the min point too. <img src = "/matlabcentral/answers/uploaded_files/29625/ijj.PNG"><pre> % code
%highest point location
[ y, x] = find(maxImage);
points = [ x y];
[d,idx] = pdist2( points, points, 'euclidean', 'Largest', 1);
idx1 = idx( d==max(d));
p={};
for i=1:length(idx1)
p{end+1} = [ points(idx1(i),1), points(idx1(i),2)];
end</pre>Nurul Najmahhttps://www.mathworks.com/matlabcentral/profile/authors/6323109-nurul-najmahtag:www.mathworks.com,2005:Question/1967992015-04-08T19:19:52Z2015-04-26T08:51:18ZHow to simulate default patternnet with feedforwardnet in Matlab?<p>I got very different training efficiency with the following network</p><pre> net = patternnet(hiddenLayerSize);</pre><p>and the following one</p><pre> net = feedforwardnet(hiddenLayerSize, 'trainscg');
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'softmax';
net.performFcn = 'crossentropy';</pre><p>on the same data.</p><p>I was thinking networks should be the same.</p><p>What thing I forgot?</p><p>UPDATE</p><p>The code below shows, that patternnet is systemtically outperforms feedforwardnet. This proves that feedforwardnet is initilized differently somehow. The question is what is the difference?</p><pre> hiddenLayerSize = 10;</pre><pre> % pass 1, with patternnet
net = patternnet(hiddenLayerSize);</pre><pre> net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;</pre><pre> [net,tr] = train(net,x,t);</pre><pre> y = net(x);
performance = perform(net,t,y);</pre><pre> fprintf('pass 1, patternnet, performance: %f\n', performance);
fprintf('num_epochs: %d, stop: %s\n', tr.num_epochs, tr.stop);</pre><pre> % pass 2, with feedforwardnet
net = feedforwardnet(hiddenLayerSize, 'trainscg');
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'softmax';
net.performFcn = 'crossentropy';</pre><pre> net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;</pre><pre> [net,tr] = train(net,x,t);</pre><pre> y = net(x);
performance = perform(net,t,y);</pre><pre> fprintf('pass 2, feedforwardnet, performance: %f\n', performance);
fprintf('num_epochs: %d, stop: %s\n', tr.num_epochs, tr.stop);</pre><pre> % pass 1, with patternnet
net = patternnet(hiddenLayerSize);</pre><pre> net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;</pre><pre> [net,tr] = train(net,x,t);</pre><pre> y = net(x);
performance = perform(net,t,y);</pre><pre> fprintf('pass 3, patternnet, performance: %f\n', performance);
fprintf('num_epochs: %d, stop: %s\n', tr.num_epochs, tr.stop);</pre><pre> % pass 2, with feedforwardnet
net = feedforwardnet(hiddenLayerSize, 'trainscg');
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'softmax';
net.performFcn = 'crossentropy';</pre><pre> net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;</pre><pre> [net,tr] = train(net,x,t);</pre><pre> y = net(x);
performance = perform(net,t,y);</pre><pre> fprintf('pass 4, feedforwardnet, performance: %f\n', performance);
fprintf('num_epochs: %d, stop: %s\n', tr.num_epochs, tr.stop);</pre><p>Output follows:</p><pre> pass 1, patternnet, performance: 0.116445
num_epochs: 353, stop: Validation stop.
pass 2, feedforwardnet, performance: 0.693561
num_epochs: 260, stop: Validation stop.
pass 3, patternnet, performance: 0.116445
num_epochs: 353, stop: Validation stop.
pass 4, feedforwardnet, performance: 0.693561
num_epochs: 260, stop: Validation stop.</pre>Olga Lodnikovahttps://www.mathworks.com/matlabcentral/profile/authors/6385072-olga-lodnikovatag:www.mathworks.com,2005:Question/2136032015-04-26T08:31:39Z2015-04-26T08:31:39ZHow to control VRealmBuilder through MATLAB<p>Hi :)</p><p>I am working on an SSVEP-based BCI and my subjects have to navigate in a virtual world (built with VRealmBuilder), using four flashing lights implemented in the virtual world to evoke their SSVEP and I'm using Emotiv EPOC to record my EEG data.</p><p>I need to know</p><p>1. How I can put four flashing lights with my four desired frequencies in my virtual world??
Should I put four lamps and control the frequency they are flashing with, through MATLAB?</p><p>And</p><p>2. How should I make the lamps have the camera coordinates?</p><p>Thanks a lot every body :)</p>Zahra Rezazadehhttps://www.mathworks.com/matlabcentral/profile/authors/6403307-zahra-rezazadehtag:www.mathworks.com,2005:Question/1530622014-09-01T13:44:02Z2015-04-26T08:07:32Zthe first argument of "warning" should be a message identifier<p>Hello, I wrote a matlab command " warning('abc'); ", but the editor detects a problem and underscores the braketed string 'abc' with red wavy line. The given information is:</p><p>The first argument of WARNING should be a message identifier. Using a message identifier allows better control over the message.</p><p>How could I get rid of this thing? Thank you!</p>Zhouhttps://www.mathworks.com/matlabcentral/profile/authors/4968535-zhoutag:www.mathworks.com,2005:Question/2133642015-04-24T11:19:51Z2015-04-26T08:05:09ZReceive value in Matlab GUI<p>Hello
I'm working with Matlab GUI using GUIDE about show status from arduino(Ex:degree,current) and I have .m file program in Matlab to calculate and read variables when I press 'Start' button. I want program to receive realtime variables. Is there any way to do to make it work? I already try to get variables but It just give me only first time value.
Here is my example of my .m file</p><pre class="language-matlab">function [B1, B2, B3, B4] = LogDataB(arduino)
mode=2;
</pre><pre class="language-matlab">fopen(arduino);
</pre><pre class="language-matlab">while mode
fprintf(arduino,'%s',1);
</pre><pre> if(mode>=1)
B1=fscanf(arduino,'%d');
B2=fscanf(arduino,'%d');%Bx
B3=fscanf(arduino,'%d');%By
B4=fscanf(arduino,'%d');%Bz</pre><pre> end</pre><pre> mode=mode-1;
end</pre><pre class="language-matlab">fclose(arduino);
</pre><p>Any idea please.</p><p>Thank you</p><p>Math</p>Thanadech Wunapeerahttps://www.mathworks.com/matlabcentral/profile/authors/6418384-thanadech-wunapeeratag:www.mathworks.com,2005:Question/918792009-06-27T01:11:00Z2015-04-26T07:28:05ZWhy can't I specify the markers for the lines in contour plots?<p>According to the documentation for CONTOUR, using the syntax CONTOUR(...,'LINESPEC'), will allow me to specify the Color and the LineStyle of the lines. It won't allow the setting of a Marker for the lines.</p><p>Why doesn't it allow the full LineSpec, including the Marker. like the PLOT function?</p>MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/2135872015-04-26T02:49:44Z2015-04-26T07:13:06Zhow to rewrite an equation in terms of another equation?<p>Hi. I have an equation for example like this:</p><p>sigma = 4*q*y^3/(b*h^3)</p><p>and I introduce that:</p><p>I = b*h^3/12</p><p>now I want to know how can I rewrite "sigma" in terms of "I"?</p>Omidreza Ghafarinejadhttps://www.mathworks.com/matlabcentral/profile/authors/6025137-omidreza-ghafarinejadtag:www.mathworks.com,2005:Question/1767002015-02-09T11:16:01Z2015-04-26T07:10:33ZCell Data, How do I access it? <p>Hi,</p><p>So I have data in this format. I want to access the data in each TD however don't know how to access it using commands. Could anyone point me in the right direction?</p><p>Thanks,</p><p>Chris</p><pre> TD(:,:,1) = </pre><pre> [512x2 double]
[ 1]</pre><pre> TD(:,:,2) = </pre><pre> [512x2 double]
[ 2]</pre><pre> TD(:,:,3) = </pre><pre> [512x2 double]
[ 3]</pre>Christopher Hallhttps://www.mathworks.com/matlabcentral/profile/authors/5488907-christopher-halltag:www.mathworks.com,2005:Question/2135992015-04-26T07:06:40Z2015-04-26T07:06:40Zsliding mode controller design<p>my system is fifth order, but transfer function shows upto powers of s^2 only ....Is the system controllabe...also help me design a PID controller using SISOTOOL..</p>Nitheesh Mhttps://www.mathworks.com/matlabcentral/profile/authors/6455372-nitheesh-mtag:www.mathworks.com,2005:Question/2135982015-04-26T07:03:55Z2015-04-26T07:03:55ZPID controller gain calculation<p>for my system tf = (0.0022s^2+ 0.0123s+6.291)/ (0.02s^2-5s-362)
please help me find a PID controller to stabilise system..I need the values of PID gains..</p><p>Its not getting controlled...response shoots to infinity</p>Nitheesh Mhttps://www.mathworks.com/matlabcentral/profile/authors/6455372-nitheesh-mtag:www.mathworks.com,2005:Question/2135972015-04-26T06:49:11Z2015-04-26T06:52:30Zcreate simulink project and run from excel vba(macro)<p>Hi,</p><p>I am new to simulink and matlab. I have fuzzy logic calculations using fuzzytech. Now i want to convert it to a matlab simulink because my fuzzytech does not support 64 bit systems.</p><img src = "/matlabcentral/answers/uploaded_files/29791/fuzzy.png"><p>How can i recreate this using simulink where i have multiple membership function as well as rule blocks. Please find the attached fuzzytech screenshot which has membership functions and rule blocks.</p>Mohammad Sherifhttps://www.mathworks.com/matlabcentral/profile/authors/6438200-mohammad-sherif