http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-12-20T02:11:01Ztag:www.mathworks.com,2005:Question/1656242014-12-05T21:12:36Z2014-12-20T02:11:01ZHow to color TriSurf faces ?<p>So... I think I understand how each triangular surface gets colored, for example:</p><pre class="language-matlab">% Pretend X, Y, and Z defined above
Tri = delaunay(X,Y);
C = Z;
trisurf(Tri,X,Y,Z,C)
</pre><p>However, it doesn't make sense (to me) why to require <b>C</b> to be the same size as <b>X</b>, <b>Y</b>, or <b>Z</b>. It would make more sense (to me) to write the <b>trisurf</b> function such that the <b>C</b> vector be the same length as <b>Tri</b> so that each face (i.e., defined by the indices in each row of <b>Tri</b>) can be colored according to some property of that specific face (e.g., the dip angle or dip direction of the face)?</p><p>Is there a work-around I am not aware of to get the desired effect? Or do I need to make my own copy of the TriSurf function and modify from there?</p>Elige Grant/matlabcentral/answers/contributors/3092678-elige-granttag:www.mathworks.com,2005:Question/1672692014-12-19T22:41:18Z2014-12-20T01:53:46ZError using a for-loop<p>The following gives an error and I don't know why. The code runs perfectly when I leave '(i_testen)' away behind 'Enkel_hoek_afg'.</p><pre> for i_testen=1:5
...
Enkel_hoek_afg(i_testen) = Enkel_hoek(1:Afg_c_RANK_RKNE(2,1))
end</pre><p>Error: In an assignment A(I) = B, the number of elements in B and I must be the same.</p>Sam/matlabcentral/answers/contributors/5925548-samtag:www.mathworks.com,2005:Question/1672682014-12-19T22:37:55Z2014-12-20T01:44:20Zexist() for functions only?<p>As I understand, the exist() function in MATLAB will return "2" if the input is a MATLAB function.</p><p>The list of options for the second input 'kind' are builtin, class, dir, file, and var.</p><p>I want to input 'kind' so that exist() will ONLY search for functions, and return 2 if it is a match to a function and a 0 if not.</p><p>Is there any way to do this?</p>Daniel/matlabcentral/answers/contributors/4784474-danieltag:www.mathworks.com,2005:Question/1671502014-12-19T01:22:50Z2014-12-20T01:34:41ZCombined value of different arrays with constraints<p>Hi!
I have a problem regarding computing combined values from arrays that not have the same size.
For a given timeseries, t, I want my for loop to compute a value if some constraints are fulfilled.</p><p>I have a vector p_dh which contains t samples where only t-n are valid and useful. Valid elements of p_dh
is given by vector A1.</p><p>Another vector A contains values where other constraints are accounted for. To compute the value, given that current element of p_dh is valid(t~= any element of A1), my plan was to use a for loop comprising som if and elseif statements. This pseudo code may be useful for understanding the problem:</p><pre class="language-matlab">for t=1:length(p_dh),
if t == any element of A1,
value(t) = nan;
elseif t == any element of A,
value(t) = p_dh(t) - p_c(t) - constant_a;
else
value(t) = nan;
end
end
</pre><p>In the end I want a vector value of size [1:4020] which has both nan elements and valid numerical values according to the for loop and given constraints.
It's worth noticing that lengths of t, A and A1 is individual. t = [1:4020], A = [1:502] and
A1 = [1:453].
Can you guys help me out here?</p><p>thanks!</p>Andreas Volden/matlabcentral/answers/contributors/5596450-andreas-voldentag:www.mathworks.com,2005:Question/1671642014-12-19T05:25:13Z2014-12-20T01:31:02ZHow to get sum of all the order values for a given id of a column in matrix<p>i have 2 columns and 10 rows</p><pre class="language-matlab">1 10
2 29
2 34
2 79
3 11
3 20
3 11
4 9
4 1
5 10
</pre><p>i want the add numbers having same value in first column
The answer i want is using loop or any other operation</p><pre class="language-matlab">1 10
2 142
3 42
4 10
5 10
</pre>Mitul saraiya/matlabcentral/answers/contributors/6000341-mitul-saraiyatag:www.mathworks.com,2005:Question/1672722014-12-20T00:13:26Z2014-12-20T01:27:02Zhow to change unit<p>hello sir, i have one question , is there any formula to change si unit of flowrate into per unit.tq</p>muhammad/matlabcentral/answers/contributors/5997891-muhammadtag:www.mathworks.com,2005:Question/1672742014-12-20T01:07:07Z2014-12-20T01:07:07Zhow to get right value of reference value of stator terminal voltage in si unit<p>hello,
the design of simulation of hidroelectric turbine are in per unit(pu) but i have change the simulation into si unit.the question is what is proper value which need i put at reference value of stator terminal voltage(Vref) which connected to AC1A excitation system?. the constant value in per unit is 1.
tq</p>muhammad/matlabcentral/answers/contributors/5997891-muhammadtag:www.mathworks.com,2005:Question/1672732014-12-20T00:55:06Z2014-12-20T00:55:06ZLPV simulation using 'pdsimul.m' Does Not work<p>I don't know how to define 'traj' (trajectory function) that used by the function pdsimul.m to simulate LPV systems.</p><p>This is my code : pdsimul(My_LPV_Sys,'traj',tf)</p><p>My_LPV_Sys : represents my LPV systems.
traj : function that represents the scheduling parameters(This is my problem, I don't know how to define that).</p><p>tf : Final simulation time.</p><p>If anyone can give me a minimum working example using pdsimul.m or give me suggestions how to define the 'traj' function, I would be obliged.</p><p>Best Regards,
Ali</p>Ali Al-jiboory/matlabcentral/answers/contributors/3735124-ali-al-jiboorytag:www.mathworks.com,2005:Question/1672662014-12-19T22:08:39Z2014-12-20T00:02:41ZOutput of For-loop in 1 file<p>I have a for-loop for 5 measurements. The first time it runs I get the output for the first measurement. The second time it runs, I get the output for the second measurement. But the output for the first measurement disappears. I know I need to save, but I want to see all the outputdata into 1 file. In 5 columns next to each other. How do I do this?</p><pre class="language-matlab">for i_testen=1:length(data_stair_rise)
RANK = data_stair_rise(1,i_testen).VideoSignals(:, strcmp('RANK', data_stair_rise(1, i_testen).VideoSignals_headers))
RANK = abs(RANK)
figure;
plot(RANK, 'g', 'LineWidth', 2);
ylabel('Distance');
xlabel('Datapoint');
title('Walking stairs', 'FontSize', 16);
legend({'Right ankle'})
xy = ginput(2);
xy(1,1) = 0;
Afstand_1schrede = xy(2,2)-xy(1,2);}
end
</pre><p>I want to save 'Afstand_1schrede' in 1 file with five columns (representing the 5 measurements op 1 subject).</p>Sam/matlabcentral/answers/contributors/5925548-samtag:www.mathworks.com,2005:Question/1672712014-12-19T23:46:41Z2014-12-19T23:46:41ZError in for-loop<pre> for i_testen=1:length(data_stair_rise) ........
Afgebakende_cyclus_RANK = xy(:,1);
Afg_c_RANK_RKNE = round(Afgebakende_cyclus_RANK);
Afgebakende_cyclus_RASI = XY(:,1);
Afg_c_RASI = round(Afgebakende_cyclus_RASI);
RKNE = data_stair_rise(1,1).VideoSignals(:, strcmp('RKNE', data_stair_rise(1, 1).VideoSignals_headers))
Enkel_hoek = data_stair_rise(1,1).VideoSignals(:, strcmp('RKneeAngles', data_stair_rise(1,1).VideoSignals_headers))
Enkel_hoek_afgerond(i_testen) = Enkel_hoek(1:Afg_c_RANK_RKNE(2,1))
end</pre><p>The last line 'Enkel_hoek_afgerond(i_testen) = Enkel_hoek(1:Afg_c_RANK_RKNE(2,1))' gives the following error: In an assignment A(I) = B, the number of elements in B and I must be the same. What should I do?</p>Sam/matlabcentral/answers/contributors/5925548-samtag:www.mathworks.com,2005:Question/1672702014-12-19T23:03:37Z2014-12-19T23:03:37ZGPU array memory restriction<p>Error using gpuArray
Out of memory on device. To view more detail about available memory on
the GPU, use 'gpuDevice()'. If the problem persists, reset the GPU by
calling 'gpuDevice(1)'</p><p>I always get this error because I have a huge variable and my gpu memory is only 4 gigs. is there a way to divide the variable in 2 portions and then copy the first part, perform the action, then copy the second part and perform the action.</p>AA/matlabcentral/answers/contributors/5703029-aatag:www.mathworks.com,2005:Question/1671212014-12-18T18:36:00Z2014-12-19T23:01:05ZHow to create a 2D circular intensity plot?<img src = "/matlabcentral/answers/uploaded_files/22753/snapshot.png"><p>Hi,
I can generate 2D plots like in the image above in comsol. I want to generate the same in matlab. This is a plot of electric field distribution in a cylindrical resonator. My matlab code has the electric field as a function of radius and angle. May be creating a meshgrid and then using polar command might be the way to go but I am not sure how to do that correctly. Any suggestion or link would be appreciated.
Thanks <a href = "</matlabcentral/answers/uploaded_files/22752/snapshot.png"></matlabcentral/answers/uploaded_files/22752/snapshot.png</a>></p>Zeba/matlabcentral/answers/contributors/2270000-zebatag:www.mathworks.com,2005:Question/1672642014-12-19T21:47:07Z2014-12-19T22:47:52Zis there any formula linking COEFF with ahat (wmpalg vs. lsqcurvefit issue) ?<p>Your lsqcurvefit function defined as depicted below:</p><pre> myfunction = @(a,T) a(1)+a(2)*Tm+a(3)*Tm.^2);
[ahat,resnorm,residual,exitflag,output,lambda,jacobian]=lsqcurvefit(myfunction,a0,Tm,Rm);</pre><p>provides a(1)=ahat(1), a(2)=ahat(2) and a(3)=ahat(3) which explicitly represent three coefficients of the second order polynomial myfunction.
On the other hand [YFIT,R,COEFF,IOPT,QUAL,X] = wmpalg(...) delivers coefficients which can be used to generate the function fit (YFIT) using the following formula:</p><pre> YFIT = P * COEFF;</pre><p>Vector P, however, is synthetized from normalized “linspased”- formatted argument, consequently COEFF array is different from that provided by ahat. Since I am not anymore quite fluent in matrix algebra (out of college long time ago), my question would be: is there any formula linking COEFF with ahat? I am trying to assemble auto-codable Simulink model and succeeded in calculating COEFF, however, for subsequent data processing in the real time I need to generate ahat.</p><p>I would be very grateful for your help</p>Gerard Malaczynski/matlabcentral/answers/contributors/1708057-gerard-malaczynskitag:www.mathworks.com,2005:Question/1672612014-12-19T21:03:54Z2014-12-19T22:43:35Z integration of FFT<p><i>I am supposed to calculate the fft of a rect function, and then getting the integration of answer.
what I have done is :</i></p><p>fs = ceil(4*pi)+1;</p><p>xend = 3;</p><p>t = (0:1/fs:xend-1/fs)-1/3*xend;</p><p>x_f = zeros([1,fs*xend]);</p><p>x_f(1,(1/3*xend*fs):(2/3*xend*fs-1)) = 5.7737e19.*ones([1,(1/3*xend*fs)]);</p><p>m_f = length(x_f);</p><p>n = pow2(nextpow2(m_f))*4;</p><p>y = fft(x_f,n);</p><p>f = (0:n-1)*(fs/n);</p><p>power = y.* conj(y)/n;</p><p>y0 = fftshift(y);
f0 = (-n/2:n/2-1)*(fs/n)/pi;</p><p>power0 = abs(y0);</p><p>plot(f0,power0);</p><p>K_fourier=power0;</p><p>K_int = int(K_fourier, -pi, pi);</p><p><i>then, I have this error:
Undefined function 'int' for input arguments of type 'double'.</i></p><p>could anyone help me please?</p><p>Thank you</p>Anita/matlabcentral/answers/contributors/5788556-anitatag:www.mathworks.com,2005:Question/1672652014-12-19T21:48:55Z2014-12-19T22:40:21ZHow to make string from matrix?<p>Hello everyone..
Can anoyne help me with this..
I have matrix with dimension 662x2 for example</p><pre> y=[111 20;123 43;117 89;....] on so on</pre><p>and form that matrix I need to make string but in every new row to put <i>'#'</i>
so matrix <i>y</i> should be converted in string like this</p><pre class="language-matlab">yy='111 20#123 43#117 89#..' and so on
</pre><p>Thank you!</p>delila/matlabcentral/answers/contributors/5918794-delilatag:www.mathworks.com,2005:Question/1672622014-12-19T21:04:58Z2014-12-19T22:27:04ZSuperimpose matrices of different sizes<p>Hello,</p><p>I have matrix A 2x5 of NaN</p><pre class="language-matlab">A=...
[NaN NaN NaN NaN NaN;
NaN NaN NaN NaN NaN]
</pre><p>and another B matrix 2x3:</p><pre class="language-matlab">B=...
[NaN 6 2;
NaN 1 0]
</pre><p>If the elements of B are postive (so not 0 nor NaN) I want to paste those elements into A, call this result matrix C</p><pre class="language-matlab">C=...
[NaN 6 2 NaN NaN;
NaN 1 NaN NaN NaN]
</pre><p>Thanks</p>Dave/matlabcentral/answers/contributors/5686285-davetag:www.mathworks.com,2005:Question/1672672014-12-19T22:18:46Z2014-12-19T22:18:46Zvpasolve with added variable 'u' in solution<p>I am solving a set of 9 equations and 9 unknowns. Using 'solve' with the symbolic toolbox, everything works perfectly. For a simplified case, I assume that one of those unknowns is known, and remove one equation that is relevant to that variable. Using 'solve' again with 8 equation and 8 unknowns, I get the error:</p><p>Warning: The solutions are parametrized by the symbols:</p><p>u = R_</p><p>v7 = R_</p><p>w5 = R_</p><p>x15 = R_</p><p>x23 = R_</p><p>> In solve at 190
In efficiency_pure_methane at 38
etaF =
x23</p><p>I tried to solve this same set of equations with 'vpasolve' and got a solution. However, the solution for the unknown that I am interested in now has a variable 'u' that is NOT a variable I have declared. What is this 'u'? Does it mean that I have infinite solutions for any value of u like the 'solve' solution may suggest? The solution is 12 lines long but the beginning looks like:</p><p>(0.5*u*(4.0*M_R*M_f*M_inf*dX_CH4...</p><p>Any insight would be appreciated!</p><p>Cheers</p>Melina/matlabcentral/answers/contributors/5796530-melinatag:www.mathworks.com,2005:Question/1667722014-12-16T05:40:18Z2014-12-19T22:11:27ZUsing Matlab in 4K resolution<p>I am using windows 8.1 and Matlab r2014a on a new 4K screen. One of the reasons for this is because I want to be able to view more code/data/figures without scrolling, etc. I have Windows set to blow up text/windows to 200% their original size because I don't like looking at small objects all the time, but I want matlab to take advantage of the high resolution and either scale the window as usual, making everything small, or just scale text in the code editor, variables, and figure windows. Figure windows are especially annoying because these items are also blown up and pixelated.</p><p>Is there a way to do such things? Is anyone else having similar experiences in Matlab after upgrading to 4K?</p>Christopher/matlabcentral/answers/contributors/4330096-christophertag:www.mathworks.com,2005:Question/1671382014-12-18T22:40:18Z2014-12-19T22:09:00Zerror with gpuarray transformation<pre class="language-matlab">>> A3 = gpuArray(q);
Error using gpuArray
Only full arrays of fundamental numeric types or logical types are
supported for GPU arrays.
</pre><p>i get the following error message. q is a cell array consisting of a matrices with many thousand rows.</p><p>my gpu is a cuda card with 4 gigabytes.</p><p>thanks</p>AA/matlabcentral/answers/contributors/5703029-aatag:www.mathworks.com,2005:Question/740312013-04-29T22:57:32Z2014-12-19T22:03:52ZHow to plot the line of best fit?<p>%Project Design
%Yellow Band
Displacemnt=[0 4 8 12 16 20 24 28 32];
Force = [0 .23 .36 .43 .52 .64 .78 .85 .92];
plot(Displacemnt, Force, 'x')
title ('Displacement vs Force');
xlabel('Displacement');
ylabel('Force');
grid
zoom on</p>Khalil/matlabcentral/answers/contributors/4093319-khaliltag:www.mathworks.com,2005:Question/1671342014-12-18T22:02:17Z2014-12-19T21:59:37ZWhy kmeans gives different results each time?<pre> * *I have square binary similarity matrix show the social relation among users, where o means no relation between two users and 1 means there is relation between them.</pre><p>I used kmeans to do clustering*</p><pre class="language-matlab">f1=dlmread('d:\matlab\r2011a\bin\paper_comm\link_flixster_bin1.txt');
c=kmeans(f1,3);
</pre><p>When run the kmeans more than one times, the results are different.</p><p>for example at firs time the
cluster 1= 4448 users , cluster 2= 434, and cluster 3=118</p><p>But, in second times
cluster 1= 4880 users , cluster 2= 119, and cluster 3=1</p><p>Why the results are different??*</p>huda nawaf/matlabcentral/answers/contributors/1077087-huda-nawaftag:www.mathworks.com,2005:Question/1660552014-12-09T18:36:17Z2014-12-19T21:53:57ZBringing battery simulation results (parameter estimation) to hardware<p>We are focused on battery modelling and SoC-Calculation for our electrical car, and already found provided tutorials really useful.
( <a href = "http://de.mathworks.com/matlabcentral/fileexchange/36019-lithium-battery-model--simscape-language-and-simulink-design-optimization">Battery Models</a> )</p><p>We've watched other battery simulation tutorials previous to this and are facing now some questions.</p><p>One big question is, how do we get the model or the simulation results later back into the car, to use the data for a live SoC-calculation in the car?</p><p>We have been thinking about creating some kind of Look-up-table out of the model, to integrate then these tables into the cars main ECU. But as we do not have any experience with this so far, we would love to know how your steps to proceed would be (assuming that the parameter estimation and everything was successful).</p><p>Attached here is one picture of our measurement files:</p><img src = "/matlabcentral/answers/uploaded_files/22330/battery_pulse_data.jpg"><p>In your opinion, is it possible to parameterize these kind of battery cell/chemistry/behaviour with the described 1RC or a 2RC?</p><p>We really appreciate your response. Thank you very much in advance for your help!</p>Valentin/matlabcentral/answers/contributors/4676022-valentintag:www.mathworks.com,2005:Question/1672632014-12-19T21:28:58Z2014-12-19T21:38:02Zxlsread can't find file but exist() can<p>Running Matlab 2014a 64 bit on Windows 7.</p><p>Occasionally, when trying to open .xls files using xlsread I get the error:</p><p>XLSREAD unable to open file '\\path\subpath\...\filename.xls'.
File '\\path\subpath\...\filename.xls'' not found.</p><p>the strings I'm using for pathname and filename are generated by using uigetfile, so Matlab can obviously see the files, which I've double checked using the exist function. I'm able to get around the problem by manually opening the Excel files and then closing them (Excel always prompts if I want to save, despite me changing nothing in the file), after which xlsread is successfully able to load the files.</p><p>These are .xls files containing macros</p>Steven Feingold/matlabcentral/answers/contributors/1470554-steven-feingoldtag:www.mathworks.com,2005:Question/1672552014-12-19T19:43:21Z2014-12-19T21:29:55Zfprintf without empty lines<p>Hi everybody,</p><p>I have some trouble with fprintf. I want to save a single line of characters in a txt-file. Later on I want to save another single line (chars again) in the same file. But there should not be any empty lines between nonempty lines in the end.</p><p>But in the way I coded my function, fprintf exports three empty lines after each line of chars.
Even if I use the control characters '\n' or '\r\n' to start a new line.</p><p>Does someone know how to fix this?</p><p>Here is my code:</p><pre class="language-matlab">filename_user_AWG = [pwd '\resource\txt\user_AWG.txt'];
output = cell2table(AWG_out_str);
writetable(output, filename_helperfile, 'Delimiter', ';', 'WriteVariableNames', false, 'WriteRowNames', false);
fid = fopen(filename_helperfile, 'r');
tempfilecontent = fread(fid,'*char')';
fclose(fid);
fid = fopen(filename_user_AWG, 'at');
fprintf(fid, '%s', tempfilecontent);
fclose(fid);
</pre><p>Greetings,
Stefan</p>Stefan/matlabcentral/answers/contributors/2997552-stefantag:www.mathworks.com,2005:Question/1672542014-12-19T19:41:32Z2014-12-19T21:28:18ZTrying to get text file to align properly for data table<p>uData is a 30x5 matrix with numbers. name_Database is a 30x1 cell array with strings of Names (e.g. Fake Subject 1, Fake Subject 2, Bob). What would fix the code so that the data aligns? (please see image for the misalignment).</p><pre class="language-matlab">ID = dbedit.uData(:,1);
scE = dbedit.uData(:,2);
ccE = dbedit.uData(:,3);
scC = dbedit.uData(:,4);
ccC = dbedit.uData(:,5);
names = dbedit.name_Database;
</pre><pre class="language-matlab">% Text file to output data into is called uDatabase.txt file.
output_file = 'uDatabase.txt';
</pre><pre class="language-matlab">% Open file for writing
fid = fopen(output_file, 'w+');
</pre><pre class="language-matlab">% Header
fprintf(fid, '%6s %12s %18s %24s %30s %36s\n', 'Name', 'ID', 'scE',...
'ccE', 'scC', 'ccC');
</pre><pre class="language-matlab">% Write the data.
for ii=1:numel(names)
fprintf(fid, '%6s %12.0f %18.0f %24.0f %30.0f %36.0f\n',names{ii},...
ID(ii),scE(ii),ccE(ii),scC(ii),...
ccC(ii));
end
</pre><pre class="language-matlab">% Close the .txt file.
fclose(fid);
</pre><img src = "http://i1243.photobucket.com/albums/gg559/ABNUCLEUS/unaligned-table_txtfile.png"><p>Text file:</p><pre> Name ID scE ccE scC ccC
Fake Subject 1 1 3 4 5 2
Fake Subject 2 2 4 3 2 5
Fake Subject 3 3 1 6 6 1
Fake Subject 4 4 2 5 3 4
Fake Subject 5 5 3 4 4 3
Fake Subject 6 6 6 1 1 6
Fake Subject 7 7 7 0 1 6
Fake Subject 8 8 4 3 3 4
Fake Subject 9 9 2 5 5 2
Fake Subject 10 10 5 2 4 3
Fake Subject 11 11 6 1 3 4
Fake Subject 12 12 5 2 2 5
Fake Subject 13 13 1 6 3 4
Fake Subject 14 14 3 4 4 3
Fake Subject 16 15 2 5 3 4
Fake Subject 17 16 1 6 1 6
Fake Subject 18 17 4 3 3 4
Fake Subject 19 18 2 5 5 2
Fake Subject 20 19 6 1 5 2
Fake Subject 21 20 3 4 1 6
Fake Subject 22 21 3 4 3 4
Fake Subject 23 22 5 2 1 6
Fake Subject 24 23 3 4 1 6
Fake Subject 25 24 7 0 3 3
Fake Subject 26 25 3 4 3 4
Fake Subject 27 26 0 0 0 0
Fake Subject 15 27 4 3 3 3
Bob 28 6 1 2 5
ludba 29 4 3 4 3
Test Subject 2 30 0 0 0 0</pre>Muaaman/matlabcentral/answers/contributors/5823965-muaamantag:www.mathworks.com,2005:Question/1672572014-12-19T20:18:39Z2014-12-19T21:26:48ZHow MATLAB move between discrete measurements <p>Hi there</p><p>when we have discrete measurements of speed or temperature, based on what MATLAB draw a scatter curve between these points ?</p><p>Thanks in advance.</p>ameen/matlabcentral/answers/contributors/4089303-ameentag:www.mathworks.com,2005:Question/1663752014-12-12T02:17:06Z2014-12-19T21:26:23ZHow to skip a parameter in a function? ex: A = fread(obj,size,'precision') without size.<p>Hello.</p><p>Is here any syntax to not enter the second input to a function while entering the third?</p><p>I like to use A = fread(s, 'uint16');</p><p>But matlab complains that 'uint16' is not valid for size...</p>David/matlabcentral/answers/contributors/5703086-davidtag:www.mathworks.com,2005:Question/1672422014-12-19T17:55:41Z2014-12-19T21:23:56ZCreate and combine quiver and contour plots<p>Im trying to figure out how to create and combine a quiver plot and a contourf using 4 vectors. I already have the quiver plot done but im stuck on the contourf. What i keep getting with the countourf is:</p><pre> Error using contourf (line 61)
Z must be at least a 2x2 matrix.</pre><pre> Error in Importingshit (line 9)
contourf(x,y,vx,vy);</pre><p>For the time being im just trying to get the contourf to work but if someone is willing to help me combine them then i would deffinitly not refuse. Thanks in advance!</p>Paul/matlabcentral/answers/contributors/5838015-paultag:www.mathworks.com,2005:Question/1672482014-12-19T18:44:00Z2014-12-19T20:58:33Zhow to generate random numbers from a distribution which is the convolution of exponential distributions?<p>Hello,</p><p>I would like to simulate two independent laser speckle intensities. Based on J. Goodman's book (Speckle Phenomena in Optics, p.39), the formula for the intensity distribution is the convolution of two exponential distributions:</p><p>p(i) = i/(I^2) exp(-i/I)</p><p>with I being the average intensity.</p><p>Is there already a function doing this? If not, how should I proceed to write it myself?</p><p>Thanks for the answer!</p><p>Cheers
Guillaume</p>Guillaume/matlabcentral/answers/contributors/5326629-guillaumetag:www.mathworks.com,2005:Question/1672602014-11-12T05:00:00Z2014-12-19T20:50:12ZWhat Amazon EC2 permissions are required to use my MDCS on demand license?<p>What Amazon EC2 permissions are required to use my MDCS on demand license?</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/1670122014-12-18T01:14:20Z2014-12-19T20:44:35ZOdd behaviour of 2x2-matrix and 2x1-vector operation<p>Consider a 2x2 matrix A with columns uncorrelated, and a vector x:</p><pre> A = [ a b ]
[-b' a']
x = [ a']
[ b']</pre><p>where a and b are complex scalar. The product of A*x is supposed to be mathematically:</p><pre> A*x = [ a*a'+b*b' ] = [ a*a'+b*b' ]
[-b'*a'+a'*b'] [ 0 ]</pre><p>In matlab 2012b, I tried to compare A*x matrix operation and the element-wise operations such as a*a'+b*b' and -b'*a'+a'*b'.
Both results happen to be different with some random pairs of a and b. a*a'*b*b' always shows positive real, but matrix operation shows some residual on the imaginary part sometime.
Even -b'*a'+a'*b' entry of matrix operation shows such erroneous imaginary part, which is supposed to be zero!</p><p>The following script finds the mismatch result and shows the hex forms of the results.</p><p>y0, y1, y2, z show the result of different operations:</p><ul><li>y0 = A*x; % matlab matrix multiply script</li><li>y1 = mtimes(A,x); % mtimes operation</li><li>y2 = mvmult_lapack (A, x); % private code using lapack routine (ZGEMV)</li><li>z = [a*a'+b*b';-b'*a'+a'*b']; % element-wise operation</li></ul><p><b>Result</b> : y2 and z are always same and real, but y0 and y1 have erroneous imaginary part. Note that the real parts of y0 and y1 are different from the real parts of y2 and z by eps, say a difference of the last bit of floating-point format.</p><p><b>Discuss and Question</b> : It is not clear why the A*x script shows the difference from the element-wise operation. It could not be a problem with LAPACK/BLAS. There seems parser or storage register problem in machine code when the matrix operation is called.
Is this only preblem with 2012b or my machine?</p><p><b>Test script</b> :</p><pre> %%
randn('seed',0)
ii=0;
while 1,
ii = ii + 1;
a = randn+i*randn;
b = randn+i*randn;
%
A = [a b; -b' a'];
x = [a'; b'];
y0 = A*x;
y1 = mtimes(A,x);
y2 = mvmult_lapack (A, x);
z = [a*a'+b*b';-b'*a'+a'*b'];
if sum(y0~=z) % break when the results are different!
break
end
if ii==10000
break
end
end
ii
%
a
b
y0
y1
y2
z
y0==z
[num2hex(real(y0)), repmat(' ',[2 1]), num2hex(imag(y0))]
[num2hex(real(y1)), repmat(' ',[2 1]), num2hex(imag(y1))]
[num2hex(real(y2)), repmat(' ',[2 1]), num2hex(imag(y2))]
[num2hex(real(z)), repmat(' ',[2 1]), num2hex(imag(z))]</pre><p><b>Output</b> :</p><pre> ii =</pre><pre> 1</pre><pre> a =</pre><pre> 1.16495351050066 + 0.626839082632431i </pre><pre> b =</pre><pre> 0.0750801546776829 + 0.351606902768522i</pre><pre> y0 = </pre><pre> 1.87930836084417 - 3.46944695195361e-18i
0 - 2.08166817117217e-17i</pre><pre> y1 =</pre><pre> 1.87930836084417 - 3.46944695195361e-18i
0 - 2.08166817117217e-17i</pre><pre> y2 =</pre><pre> 1.87930836084417
0</pre><pre> z =</pre><pre> 1.87930836084417
0</pre><pre> ans =</pre><pre> 0
0</pre><pre> ans =</pre><pre> 3ffe11a5a4cecd1e bc50000000000000
0000000000000000 bc78000000000000</pre><pre> ans =</pre><pre> 3ffe11a5a4cecd1e bc50000000000000
0000000000000000 bc78000000000000</pre><pre> ans =</pre><pre> 3ffe11a5a4cecd1d 0000000000000000
0000000000000000 0000000000000000</pre><pre> ans =</pre><pre> 3ffe11a5a4cecd1d 0000000000000000
0000000000000000 0000000000000000</pre>Sung-Eun Jo/matlabcentral/answers/contributors/1329294-sung-eun-jotag:www.mathworks.com,2005:Question/1672282014-12-19T15:12:22Z2014-12-19T20:44:34ZCan we define operators in MATLAB?<p>I started learning OOP in MATLAB and I saw that we can either use the colon(A,B) syntax or simply A:B. This kind of method works for other operators and we may even redefine how they work.</p><p>My question is: can we somehow achieve that MATLAB recognises some other symbols we define? For example, I want to use ° for dyadic product in my class and if I typed A°B, dyadic(A,B) would be executed on objects A and B.</p>Zoltán Csáti/matlabcentral/answers/contributors/2924415-zoltan-csatitag:www.mathworks.com,2005:Question/1672522014-12-19T19:10:00Z2014-12-19T20:42:40ZDear Users I have the energy.txt file and i need ti extract two columns data from this file [No ,Levels]<p>Dear Users I have the energy.txt file and i need ti extract two columns data from this file [No ,Levels]</p><pre class="language-matlab">The following file as follow:
nblock = 1 ncftot = 79 nw = 9 nelec = 3 nblock = 2 ncftot = 186 nw = 9 nelec = 3
Energy levels for ...
Rydberg constant is 109737.31534
No - Serial number of the state; Pos - Position of the state within the
J/P block; Splitting is the energy difference with the lower neighbor
-------------------------------------------------------------------------
No Pos J Parity Energy Levels Splitting
1 1 1/2 + -34.7830481 0.00000 0.00000
2 1 1/2 - -34.4869723 64981.12 64981.12
3 1 3/2 - -34.4863648 65114.46 133.33
</pre><p>Then i need to plot the No versus levels columns.Any one could help me as soon please. RGD/mahmoud</p>mahmoud el majzoub/matlabcentral/answers/contributors/6001790-mahmoud-el-majzoubtag:www.mathworks.com,2005:Question/1672582014-12-19T20:19:50Z2014-12-19T20:38:23Zhow can i get ode15s ??<p>i always get ode45 by default but i need ode15s</p>arwa/matlabcentral/answers/contributors/5116407-arwatag:www.mathworks.com,2005:Question/1671352014-12-18T22:12:03Z2014-12-19T20:37:39ZWrite an expFit function that calls linefit to fit data to y = C1*e^(C2*x)<p>Hey guys, I'm not quite sure where to start with this one. I was hoping to find some guidance as to what direction I need to take in order to get the desired result, and also what the whole concept is behind this. ANY help is highly valued so PLEASE feel free to respond with anything you got. Time is of the essence in the engineering world.</p><p>I saw the thread that contained the same question that I am asking but not much was answered in that thread so I thought I would make one that tailored to my specific questions and parameters.</p><p>This problem is based on converting non-linear relationships into linear ones, so that linear
regression methods can be applied for fitting.</p><p>The question states, "Write an expFit function that calls linefit to fit data to y = C1*e^(C2*x)"
Then it gives us the following data in order to test our function...</p><p>x = [1, 2.5, 4, 5.5, 7]
y = [2.285, 1.417, 0.879, 0.545, 0.338]</p><p>I hope this can be a learning experience for me as I really want to improve in this area of coding, so please share any knowledge or concepts related to this topic.</p>Ryan/matlabcentral/answers/contributors/5999865-ryantag:www.mathworks.com,2005:Question/992652013-03-20T13:05:00Z2014-12-19T20:35:07ZHow do I download an older version of MATLAB?<p>How do I download an older version of MATLAB?</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/1672592014-11-06T05:00:00Z2014-12-19T20:35:07ZHow do I configure my firewall to connect to my Amazon EC2 cluster for my MDCS on demand license?<p>I am attempting to configure my MATLAB client in order to connect to my MDCS cluster using MATLAB Hosted License Manager on Amazon EC2, what ports are required to be open for communication?</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/1430272014-07-23T13:10:03Z2014-12-19T20:31:05Zsurf() plots weird black lines<p>Hi,</p><p>the surface plot contains weird lines that connect edges of the surface. For example the following code:</p><pre class="language-matlab">x = -3:0.1:3;
y = -3:0.1:3;
[xx,yy] = meshgrid(x,y);
zz = xx.^2 - yy.^2;
surf(xx,yy,zz);
</pre><p>plots this:</p><img src = "/matlabcentral/answers/uploaded_files/15752/untitled.png"><p>surprisingly when I File->Save As, those lines are gone from the output image file.</p><p>I'm using version: 8.2.0.701 (R2013b)
Is this a bug? There appears to be a similar question here: <a href = "http://www.mathworks.com/matlabcentral/answers/52846-surf-command-gives-false-lines">http://www.mathworks.com/matlabcentral/answers/52846-surf-command-gives-false-lines</a></p><p>I know I can disable lines with: 'EdgeColor', none. But I want the grid because it helps me visualize.</p>Donald K/matlabcentral/answers/contributors/4806493-donald-ktag:www.mathworks.com,2005:Question/1672562014-12-19T19:53:11Z2014-12-19T20:22:05ZDetermining the intersection of two vectors<p>Below is my working code for a simple program to graph two vectors.</p><p>line([0,50],[30,30]);
line1 = [0 30 50 30 ];</p><p>line([55,55],[15,30]);
line2 = [55 15 55 30];</p><p>C = intersect(line1,line2)</p><p>Below is the visual representation of these two lines:</p><img src = "/matlabcentral/answers/uploaded_files/22806/Capture.PNG"><p>It is barely visible in the top right corner that these two lines do not intersect. intersect(A,B) however indicates they're intersecting at 30. I assume this is because it treats the vectors as lines which extend forever? Is there any functionality for matlab which would handle only the given space as opposed to infinite length? It should ideally return these lines do not intersect.</p><p>Thanks!</p>Jack/matlabcentral/answers/contributors/3050725-jacktag:www.mathworks.com,2005:Question/1672532014-12-19T19:31:37Z2014-12-19T20:20:44ZUsage Of "goto" for previous lines<p>hello guys
Iva had a simple but confusing question... i was writing a program for Euler's formula, then I found out Matlab doesn't have any "goto" function for refering to previous lines . i was looking for an alternate and i will appreciate it if you guys help me with this :)
here's an example:</p><pre> x=[0.1:0.1:1]
h=0.1
i=1
y(1)=1
Z(1)=1.1
Y(1)=1.1
%Y'=y*(x^(1/3))
while i<11
y(i+1)=y(i)+(h*(x(i)*(y(i)^(1/3))))
Z(i+1)=(x(i+1)*(y(i+1)^(1/3)))
line** y(i+1)=y(i)+(0.5*h*(Y(i)+Z(i+1)))
Y(i+1)=x(i+1)+y(i+1)
if abs(Y(i+1)-Z(i+1))>0.00000000001
Z(i+1)=Y(i+1)
goto(line**)
end
i=i+1
end</pre>Hossein/matlabcentral/answers/contributors/6001849-hosseintag:www.mathworks.com,2005:Question/1670372014-12-18T06:38:27Z2014-12-19T19:51:55Zwhy reference matrix is shown as empty matrix when I am reading a geo tiff file from matlab 2010a?<p>I imported modis images(reprojected to geographic coordinate system) in matlab 2010.But, reference matrix is shown as empty one and I cant find geographic coordinate of interesting points. Plz can you explain where I was wrong and give a solution for me. Thanks.</p>tharaka suranjan/matlabcentral/answers/contributors/5316163-tharaka-suranjantag:www.mathworks.com,2005:Question/1672462014-12-19T18:31:30Z2014-12-19T19:45:52ZHow to extract every other value from a 50000x1 array?<p>Hello.</p><p>I have a problem I can't solve. I read in values over a serial COM port, the valuea are 12bit ADC results but I need to send them as:</p><pre> value = ADC_reading;
Serial.write(value >> 8);
Serial.write(value & 0xFF);</pre><p>So when received in matlab its a stream of value pairs, for example:</p><p>2 251 2 251 2 251 2 251 2 251 2 251 2 251 2 251 2 251 2 251 2 251 2 251...
though I store them as a n x 1 vector.</p><p>How can I process this vector?</p><p>I have been on the path of reading only one pair of values one byte at a time in some loop but that does not seem to be a good idea at all, I get problem when trying to solve the end value vector indexing.If there is no solution to this I 'could' send the values in its hole form but that will take at least 5 bytes per value and I am going out of my way to squeezing every little efficiency out of the setup in order to achieve as high a data throughput as possible.</p><p>Regards</p>David/matlabcentral/answers/contributors/5703086-davidtag:www.mathworks.com,2005:Question/1670832014-12-18T12:34:29Z2014-12-19T19:32:32Zhow can i generate an exe file that contains java robot<p>i had used java robot but when i made exe file it didn't work. I guess I must add java file to deploytool but I couldn't find java.awt.Robot file</p><p>sincerely</p>Amirhosein Ghenaati/matlabcentral/answers/contributors/5863976-amirhosein-ghenaatitag:www.mathworks.com,2005:Question/1672442014-12-19T18:03:31Z2014-12-19T19:29:01ZVisualisation of vector data in matlab<p>Hi,</p><p>I have x,y,z (three 400*1 vectors )data which correspond to a 2-D grid (x,y) of a channel and the flow depth (z) at the grid points.</p><p>I want to have a plot of the flow depth for each point in the grid. How can I do so? I already tried, mesh, surf, plot3d, and contour. None of them works. The problem is the same for all of them: " z needs to be a matrix". While my z is a vector since it represents a single value of the fluid depth.</p><p>Would you please help me how I can proceed?</p><p>Many thanks.</p>R/matlabcentral/answers/contributors/6001717-rtag:www.mathworks.com,2005:Question/1672472014-12-19T18:39:32Z2014-12-19T19:26:03Zerror message from 'fsolve'<p>Hello,</p><p>Will you please spare a few second to help clarify what went wrong with my code, I am getting the following message:</p><pre class="language-matlab">Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
> In fsolve at 285
In paper2_vL1 at 89
</pre><pre class="language-matlab">No solution found.
</pre><pre class="language-matlab">fsolve stopped because the relative size of the current step is less than the
selected value of the step size tolerance, but the vector of function values
is not near zero as measured by the selected value of the function tolerance.
</pre><p>I will post the code if required. I guess it has to do with my initial values?
Thank you
R.</p>R/matlabcentral/answers/contributors/5535528-rtag:www.mathworks.com,2005:Question/1672162014-12-19T12:10:28Z2014-12-19T19:25:44ZGenetic Algorithm (GA) with integer, equality and inequality constraint<p>Hi all,</p><p>I try to solve a complex problem as fast as possible using various optimization techniques.
With the Genetic Algorithm, some problems arise:
I have to combine equality, inequality and integer constraints (only part of the X vector), which is not possible with the ga function.
The equality constraints deal with the non-integer variables.
This far, I've used some techniques to work around this, but they didn't prove very succesful yet:</p><p>1) Let GA look for the integers only,
In the evaluation of the fitness of individuals, call a linprog which optimizes the other variables
and makes sure the equality constraints are ok. The linprog makes fitness evaluation really slow.</p><p>2) Replace the equality constraint by two inequality constr (Ax<=b and Ax>=b), but this renders the problem with a lot of constraints and no feasible solution is found in a 'normal' timeframe.</p><p>Are other techniques possible or does anyone have tips which might help to solve this complex problem with much constraints?</p><p>Kind regards</p>Kobe Geryl/matlabcentral/answers/contributors/4249017-kobe-geryltag:www.mathworks.com,2005:Question/1669322014-12-17T10:51:49Z2014-12-19T19:22:05ZHow can I write a program to make someone input a 6 digit number and show a result of the summation of the 6 digits?<p>Anybody know the functions I need?</p>Kristian/matlabcentral/answers/contributors/5993227-kristiantag:www.mathworks.com,2005:Question/1672492014-12-19T18:44:38Z2014-12-19T19:06:43ZWriting function that ether gives as a result or that uses a two-dimensional array as input?<p>Hello.</p><p>I have been trying for hours to get a function to work as for example</p><pre> function [data] = failure(value, somethingElse)</pre><p>where data is a 2x2048 double array, or value being a 2x2048 double array.
I don't need both to be 2x2048 but I fail to make any function using such a variable, does any one know how a function using that kind of variables would look like?</p><p>Regards</p>David/matlabcentral/answers/contributors/5703086-davidtag:www.mathworks.com,2005:Question/1672502014-12-19T18:55:21Z2014-12-19T19:01:15ZHow do I create a For-loop for these 5 subjects?<p>In the attached files there is a figure of my data (being 'data_stair_rise') (5x5). Each cell being a struct. Row 1 stands for subject 1 and the 5 columns are the 5 measurements of the subject.
I've made a code (a for-loop) which calculates the 'Distance_1step' for subject 1.
I've tried to adjust my for loop, so it calculates the 'Distance_1step' for all 5 subjects. But I can't seem to find it.</p><p>My code is:</p><pre class="language-matlab">for i_pp = 1:length(data_stair_rise)
RANK = data_stair_rise(1,i_pp).VideoSignals(:, strcmp('RANK', ...
data_stair_rise(1,i_pp).VideoSignals_headers) %RANK = Right Ankle
RANK = abs(RANK)
figure;
plot(RANK, 'g', 'LineWidth', 2);
ylabel('Distance');
xlabel('Framenumber');
title('Walking stairs', 'FontSize', 16);
legend({'Right ankle'})
xy = ginput(2);
Distance_1step(i_pp) = xy(2,2)-xy(1,2);
end
</pre>Sam/matlabcentral/answers/contributors/5925548-samtag:www.mathworks.com,2005:Question/1672512014-12-19T18:55:21Z2014-12-19T18:55:21ZMatlab multitasking without using Parallel Computing Toolbox?<p>Hello.</p><p>I am a novice in programming in general, but I am using a arduino Due which is using a SAM3X8E 32bit mcu.
SAM3 has both DMAC(Direct Memory Access Controller) and PDCs(Peripheral DMA Controller) which allows me for example to setup the ADC to continuously convert and store the results in a array without the CPU doing any of it. So I am free to preform other tasks at the same time.</p><p>A PC is far more powerful but is there any way to write a script to do many(or two) things at the same time as akin to DMA?</p><p>Maybe continuously reading a serial port for values to plot or process at the same time, using a ping-pong buffer.</p><p>Regards</p>David/matlabcentral/answers/contributors/5703086-david