https://jp.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — 新規の質問2017-12-14T14:54:24Ztag:jp.mathworks.com,2005:Question/3728072017-12-13T19:03:12Z2017-12-14T14:54:24ZIs it possible to shut down raspberry pi on simulink?<p>Is it possible to shut down raspberry pi on simulink?</p>Andrea Piscullihttps://jp.mathworks.com/matlabcentral/profile/authors/9749737-andrea-piscullitag:jp.mathworks.com,2005:Question/3729412017-12-14T12:51:52Z2017-12-14T14:54:05Ztwo for Nested Loops<p>How i can sum the third column to get the average over each 24 values of the second coloumn?</p>ahmad Saadhttps://jp.mathworks.com/matlabcentral/profile/authors/4269191-ahmad-saadtag:jp.mathworks.com,2005:Question/3729612017-12-14T14:53:12Z2017-12-14T14:53:12ZWhen I fit data to a poisson distribution using histfit, I'm unable to see the fitted function, only the histogram - why?<p>Here's my code, which is pretty generic.</p><pre class="language-matlab">bin = 30;
</pre><pre class="language-matlab">% Fit a poisson distribution
histfit(x(x > 0),bin,'poisson')
</pre><p>When I fit the data using apparently any other distribution - e.g. normal, weibull, beta, etc. - I don't have a problem.</p>Shttps://jp.mathworks.com/matlabcentral/profile/authors/6274820-stag:jp.mathworks.com,2005:Question/3728422017-12-13T23:44:30Z2017-12-14T14:52:54ZPrecision lost when change numbers to string<p>Hi I am trying to use the following to generate a string. A is is 1D array containing 4 real numbers that have large decimal precisions</p><pre class="language-matlab">A=[0.000002101, 0.000000225567 ,1.20004136789, 66.000052353]
</pre><pre class="language-matlab">ST=strjoin( string('Hi ') + A.', newline )
</pre><p>However string 'ST' trims or rounds off my numbers. How can I create the string ST with exact numbers in A?</p><pre class="language-matlab">fid = fopen('ny.txt','wt');
fprintf(fid, '%s', ST);
fclose(fid);
</pre>H Hhttps://jp.mathworks.com/matlabcentral/profile/authors/6560727-h-htag:jp.mathworks.com,2005:Question/3729602017-12-14T14:52:36Z2017-12-14T14:53:28ZSolving A{k} * x + b = 0 for large numbers of A{k} with same structure/filling.<p>Dear all,</p><p> I am trying to improve the efficiency of solving <tt>A{k}*x+b=0</tt> for <tt>x</tt>, that I currently solve using the <tt>\</tt> operator iterating through <tt>k=1:Nk</tt> typically with <tt>Nk</tt> in <tt>1E4-1E5</tt>.</p><p><tt>A{k}</tt> are square, non-symmetrical, large ( <tt>NxN</tt> with <tt>N</tt> in <tt>1E5-5E5</tt>) sparse matrices (typical density <tt><1E-4</tt>), <i>column strictly diagonally dominant</i>. They all have the same (block) structure/filling :</p><img src = "/matlabcentral/answers/uploaded_files/98541/A_filling.png"><p> </p><p>and <tt>b</tt> is <tt>Nx1</tt> with <tt>nnz(b)</tt> typically in <tt>1-1E4</tt>.</p><p>I discussed the case <tt>A*x+B=0</tt> already for <tt>B</tt> <tt>NxM</tt> with <tt>M</tt> large, where I can take advantage of a <tt>LU</tt> factorization of a single <tt>A</tt> and solve in parallel:</p><pre class="language-matlab">[L, U, P, Q, R] = lu( A ) ;
parfor ...
X{k} = Q * (U \ (L \ (P * (R \ B_cell{k}))))
end
</pre><p>where <tt>B_cell</tt> splits <tt>B</tt> in blocks of appropriate size, in <a href = "https://www.mathworks.com/matlabcentral/answers/309690-improving-performance-of-x-a-b">this thread</a>.</p><p>My question now is, is there a transformation/factorization that I could use, that exploits the fact that all <tt>A{k}</tt> have the same filling/structure, that I would apply e.g. to <tt>A{1}</tt> and then re-use to accelerate solving <tt>A{k}*x+b=0</tt> for all other <tt>A{k}</tt>? Could the block-structure and the partial filling of <tt>b</tt> be used in any manner?</p><p>Typical <tt>A{k}</tt> and <tt>b</tt> can be <a href = "http://www.pangea-model.org/other/TMW/A_b.mat">downloaded here as a MAT File</a>.</p><p>Cheers,</p><p>Cedric</p>Cedric Wannazhttps://jp.mathworks.com/matlabcentral/profile/authors/1078046-cedric-wannaztag:jp.mathworks.com,2005:Question/3728082017-12-13T19:04:01Z2017-12-14T14:51:11ZHow can I plot slope including maximum peaks?<img src = "/matlabcentral/answers/uploaded_files/98456/hshshshsh.png"><p>Hello,
How can I plot slope including peaks point? It should look like exp. I tried envelope but It does not work for my code.</p><p>Thank you.</p>Ezgi Ertunçhttps://jp.mathworks.com/matlabcentral/profile/authors/6240805-ezgi-ertunctag:jp.mathworks.com,2005:Question/3725252017-12-12T10:20:47Z2017-12-14T14:51:00ZLog data Simulink-Arduino Uno on Sd card<p>Hi! I'm running a Simulink model in the Arduino Uno board and at the end of the simulation I'd like to save the results in the Sd card attached to the board. How can I do it? Thanks for your help!</p>Giorgio Concuhttps://jp.mathworks.com/matlabcentral/profile/authors/11031096-giorgio-concutag:jp.mathworks.com,2005:Question/3728502017-12-14T01:04:08Z2017-12-14T14:48:59ZAbout summing of anonymous function<p>Hi.
I'm using matlab on my research at the university and an optimization protocol which is fmincon function.
Although I make the formula like, y =@(x)(x(1)+1)^2 + (x(2)+5)^2, as my research progresses, the formula will be much longer and complex.
So I'd like to dismantle this function like
y1=@(x)(x(1)+1)^2 + (x(2)+5)^2;
y2=@(x)(x(3)+21)^2 + (x(4)+10)^2;
after that , connect them like
y = y1 + y2;</p><p>I tried this, but failed.
Do you know how to deal with it?</p>Kazuma Yamashitahttps://jp.mathworks.com/matlabcentral/profile/authors/10919875-kazuma-yamashitatag:jp.mathworks.com,2005:Question/3725682017-12-12T14:33:55Z2017-12-14T14:47:00ZHow Are Calculations Done for Variable That's Inclusive of Itself?<p>Consider the following simple scenario:</p><pre class="language-matlab">x=x+1
</pre><p>In terms of computational efficiency and speed, I'm curious how this calculation is handled. x is inclusive of itself and overwriting itself with a new value. So I assume x has to first be moved to RAM to then complete the calculation and subsequently store the new value. I have a very large script, with large matrices, many loops, and lots of similar calculations. The script takes a long time to run and I'm wondering if this is a bottleneck that slows down the script. An alternative might be as follows, but I'm not sure if I'd gain anything.</p><pre class="language-matlab">temp=x
x=temp+1
</pre><p>In this latter case, x is not inclusive of itself in the calculation, so I wonder if this is more efficient.</p><p>I'd appreciate any input.</p><p>Thanks,</p><p>M Ridzon</p>Matthewhttps://jp.mathworks.com/matlabcentral/profile/authors/1259708-matthewtag:jp.mathworks.com,2005:Question/3729482017-12-14T13:47:01Z2017-12-14T14:46:06ZImport a .txt file with numbers and words<p>I need to import a .txt file that with numbers and words. In particular I need the first two numbers next to every "POINT" and the first number after "PATH", how can I do this?</p><p>I tried to import the .txt file using "Import Data" but this operation is too slow.</p><p>Thank you.</p><img src = "/matlabcentral/answers/uploaded_files/98529/Schermata%202017-12-14%20alle%2014.37.04.png">Dario Anghilerihttps://jp.mathworks.com/matlabcentral/profile/authors/5831727-dario-anghileritag:jp.mathworks.com,2005:Question/3729342017-12-14T11:45:42Z2017-12-14T14:46:03ZHow to import file.dat to matlab without delimiter<p>Hi
I have file.dat that contain data like this</p><p>7756|01/01/2016 00:15:00|182.422478353023|33554432</p><p>7756|01/01/2016 00:30:00|170.79956543853|33554432</p><p>How to extract these data in 4 column by delimiting '|' ?</p>Pradya Panyainkaewhttps://jp.mathworks.com/matlabcentral/profile/authors/11731653-pradya-panyainkaewtag:jp.mathworks.com,2005:Question/3729592017-12-14T14:44:34Z2017-12-14T14:44:34ZHow to design convolution neural network without library function? Give me some idea<p>I want to implement CNN without library function..I know how it work but i can not understand how to code please give some idea</p>kiron ahmedhttps://jp.mathworks.com/matlabcentral/profile/authors/8590312-kiron-ahmedtag:jp.mathworks.com,2005:Question/3727412017-12-13T13:15:59Z2017-12-14T14:44:21ZError linking Simulink Test to DOORS requirements<p>Has anyone had success linking a Simulink Test Case to a requirement in a DOORS module?
Using R2017b.
With a DOORS 9.6.1.9 database I have the ability to run DXL scripts, and I have been told by the administrator the ability to run DXL on our DOORS 9.x databases isn't restricted and there is no 'Edit DXL' privilege.</p><p>I am getting error "MATLAB cannot find the DOORS automation server. You must have "Edit DXL" access privileges in your DOORS login account to use the DOORS interface..." when I click the Add button in Test Manager</p>Andrew Devinehttps://jp.mathworks.com/matlabcentral/profile/authors/11653103-andrew-devinetag:jp.mathworks.com,2005:Question/3728672017-12-14T04:05:43Z2017-12-14T14:40:31ZToo many output arguments!!!<pre class="language-matlab">function PPM_code
PPM_code_internal(2,6);
</pre><pre class="language-matlab">function PPM_code_internal(M,nsym)
% function to generate PPM
% 'M' bit resolution
% 'nsym': number of PPM symbol
a=[];
for i= 1:nsym
temp=randi(1,M); % random binary number
dec_value=bi2de(temp,'left-msb'); % converting to decimal value
temp2=zeros(1,2^M); % zero sequence of length 2^M
temp2(dec_value+1)=1; % placing a pulse according to decimal value
% note that in matlab index does not start from zero, so need to add 1;
a=[PPM_code temp2]; % PPM symbol
end
</pre><p>When I execute the code above, I will have an error of</p><pre class="language-matlab">Error using ==> PPM_code
Too many output arguments.
</pre>Alex Phanghttps://jp.mathworks.com/matlabcentral/profile/authors/11724246-alex-phangtag:jp.mathworks.com,2005:Question/3724622017-12-12T02:24:19Z2017-12-14T14:39:26ZGroup bar graph, with different group sizes?<p>Hi all,</p><p>I'm trying to make a bar graph with groups - but not all groups are the same size.</p><p>My current code is as follows:</p><pre> y = [13.2764279; -2.011230558 5.146663618 5.7332464; -22.2335537 -5.60238553 -4.9771596; -47.575537 -18.405 -23.2868517];
figure1=figure;
bar(y)
xticklabels({'Baseline';'10% Perennials, 10% Reduction'; '10% Perennials, No reduction'; 'No increase, 10% Reduction';'25% Perennials, 25% Reduction'; '25% Perennials, No reduction'; 'No increase, 25% Reduction';'50% Perennials, 50% Reduction'; '50% Perennials, No reduction'; 'No increase, 50% Reduction'});
xtickangle(45)
xticks(1:1:length(category))</pre><p>Besides adding in 0 or NaN - are there any other options? Thanks for the help!</p>Tracy Campbellhttps://jp.mathworks.com/matlabcentral/profile/authors/10258319-tracy-campbelltag:jp.mathworks.com,2005:Question/3728772017-12-14T05:41:34Z2017-12-14T14:39:05ZMoving between the condition<p>I am trying to replace an array values less than the orginal by generating random values between some range among them. I tried but the values are replaced by larger values than the orginal in some cases. So i have to use another condition to check this case and have to redo the random generation if the value goes greater than its original. I don't know how to jump again to the condition.Here is my code</p><pre> for i= 1 :x
v = value(i);
if(v>=min_value) && (v<=p10)
rval = min_value + rand * (p10 - min_value);
*if (rval<v)
new(i,cnt+1) = rval;
else*</pre><pre> elseif (v>p10) && (v<=p20)
new(i,cnt+1) = p10+ rand * (p20 - p10);
*if (rval<v)
new(i,cnt+1) = rval;
else*
end
end</pre>Vennila Gangatharanhttps://jp.mathworks.com/matlabcentral/profile/authors/3920913-vennila-gangatharantag:jp.mathworks.com,2005:Question/3717672017-12-07T21:20:41Z2017-12-14T14:36:03ZConfusion Matrix Results Sensitivity<p>How do I calculate the sensitivity and specificity with the confusionmat command? What is the position of TP, FP, FN, TN in the confusion matrix provided by matlab? I use the "confusionmat".</p>Gledson Melottihttps://jp.mathworks.com/matlabcentral/profile/authors/7172134-gledson-melottitag:jp.mathworks.com,2005:Question/3727842017-12-13T16:48:31Z2017-12-14T14:35:32ZWhat is the most efficient way to find the position in the column of a matrix where the value drops below a given threshold (values are constantly decreasing down the columns)?<p>I have a large (up to 1000x1000) matrix which is the solution to a pde - the columns are the increments in time and the rows are the increments in space. The values down each column are decreasing and I want to find the row of each column where the value drops below a certain value (1 in the code below) and store these values in a vector where the value at each position is the row where it drops below the threshold. My method works perfectly well but is very slow, is there a better way?</p><p>My code:</p><pre class="language-matlab">timeivector = 2:state.Numberoftimesteps; %starts at 2 since initial condition is zero everywhere
spaceivector = 1:state.Numberofspacesteps;
</pre><pre class="language-matlab">for ti = timeivector
for xi = spaceivector
if largematrix(xi,ti) <= 1
continue
end
outputvector(ti) = xi+1;
end
end
</pre>J2A2B2https://jp.mathworks.com/matlabcentral/profile/authors/7101258-j2a2b2tag:jp.mathworks.com,2005:Question/3729542017-12-14T14:12:34Z2017-12-14T14:34:35ZFourier Transform on a .wav File<p>Hi,</p><p>I have a .wav file. When you play this now, you will only hear noise. But there is a hidden message in it. To hear what the message is, I will have to perform a Fourier Transformation. I tried a lot of things, but nothing works and I really don't know why.</p><pre class="language-matlab">[y,Fs] = audioread('Audiofile.wav')
x = fft(y)
audiowrite('Fourier.wav',x,Fs)
</pre><p>This is what I have right now, but still I only hear noise... When I plot the data, nothing appears, just an empty plot...
I would be really happy if someone could help me with this problem!</p>Annika Brenkmanhttps://jp.mathworks.com/matlabcentral/profile/authors/11654388-annika-brenkmantag:jp.mathworks.com,2005:Question/3728752017-12-14T04:41:27Z2017-12-14T14:34:15ZConvert Matlab function to Mex file - For loop conversion<p>I am trying to optimize my code by converting the following for loop to mex file. However, I am having a few problems converting them. Can anyone help me ?</p><pre> Ixyz1 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz2 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz3 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz4 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz5 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz6 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz7 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz8 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz9 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');
Ixyz10 = zeros(xgridsize * ygridsize * zgridsize, 1,'single');</pre><pre> for i = 1:1:length(Ixyz1)
Ixyz1(i) = Ixy(timedifference1(i) + 2001,1);
Ixyz2(i) = Ixy2(timedifference2(i) + 2001,1);
Ixyz3(i) = Ixy3(timedifference3(i) + 2001,1);
Ixyz4(i) = Ixy4(timedifference4(i) + 2001,1);
Ixyz5(i) = Ixy5(timedifference5(i) + 2001,1);
Ixyz6(i) = Ixy6(timedifference6(i) + 2001,1);
Ixyz7(i) = Ixy7(timedifference7(i) + 2001,1);
Ixyz8(i) = Ixy8(timedifference8(i) + 2001,1);
Ixyz9(i) = Ixy9(timedifference9(i) + 2001,1);
Ixyz10(i) = Ixy10(timedifference10(i) + 2001,1);
end</pre><p>timedifference1 to timedifference10 have the same size as Ixyz1 to Ixyz10.</p><p>xgridsize , ygridsize are usually greater than 200. and zgridsize is around 100.
Ixy to Ixy10 have the same size of 4000*1.</p>aa39998https://jp.mathworks.com/matlabcentral/profile/authors/5596525-aa39998tag:jp.mathworks.com,2005:Question/3729062017-12-14T09:04:16Z2017-12-14T14:30:58ZDisplay comma instead of dot at contour levels?<p>Hello everyone,</p><p>the title is basically my whole question. I want to change the labels on the contour levels of a contour plot so that the numbers have a comma instead of a dot (its a german thing).</p><p>I've read that following code would have worked in older versions of Matlab - C and h being the outputs of the contour function:</p><pre class="language-matlab">acl=clabel(C,h,'FontSize',10,'Color','k');
for i=1:length(acl)
oldlabel=get(acl(i), 'String');
newlabel=strrep(oldlabel, '.', ',');
set(hcl(i),'String',newlabel);
end
</pre><p>In the Matlab version I'm using, clabel is returning a "GraphicsPlaceholder"-Object, which I cannot change in the same way.
How would I change the labels in Matlab version R2017a ?</p><p>(Same question has been posted <a href = "http://www.gomatlab.de/konturplot-labels-mit-komma-statt-punkten-t45158.html">here</a> in german)</p>Ingo Rückhttps://jp.mathworks.com/matlabcentral/profile/authors/10432812-ingo-rucktag:jp.mathworks.com,2005:Question/3729432017-12-14T13:16:25Z2017-12-14T14:27:33ZKnow Formula used in function Matlab <p>Good morning everyone!</p><p>I'm developing C++ software for my project using 3d accelerometer/gyroscope MPU6050, and I would like to know the formula used by Matlab for a general function__, let's say the " <i>source code</i>" that explain the math behind the objects functions, for example the function <b>interp3</b></p><p>Of course the same is for other functions used.</p><p>Thank you very much for your attention!
Have a nice day,
FC</p>Francesco campagnahttps://jp.mathworks.com/matlabcentral/profile/authors/8942133-francesco-campagnatag:jp.mathworks.com,2005:Question/3497732017-07-21T19:14:59Z2017-12-14T14:27:18Zcan't view confusion matrix in matlab<p>Could you help me , I want to show my confusion matrix in readable view, as I have 18 classes so I got non readable confusion matrix when I click confusion button on neural network tool box like that image</p><img src = "/matlabcentral/answers/uploaded_files/83505/untitled2.jpg"><p>Please help me to view it like this</p><img src = "/matlabcentral/answers/uploaded_files/83506/may%20test.jpg"><p>I tried plotconfusion function but I got the all confusion matrix but I need the training and testing matrix</p>sherok mohamedhttps://jp.mathworks.com/matlabcentral/profile/authors/10314421-sherok-mohamedtag:jp.mathworks.com,2005:Question/3729582017-12-14T14:26:23Z2017-12-14T14:26:23ZPass GUI data to another .m file/function and from that to workspace<p>Hello.
I am trying to make a GUI using GUIDE. For starters it will have a popupmenu and a pushbutton.</p><p>Things I have changed in the default-generated code:</p><p>In <i>popupmenu1_CreateFcn</i> to only show specific file extensions:</p><pre class="language-matlab">d = [dir('*.txt'); dir('*asc.dat')];
set(hObject, 'String', {d.name});
</pre><p>and in <i>pushbutton1_Callback</i> to get the filename:</p><pre class="language-matlab">handles.answer = get(handles.popupmenu1, 'Value');
</pre><p>I tried to write the filename into the figure's 'answer' path, I don't know if that is correct.</p><p>I then want to get that filename and enter it into another function in another .m file, that uses it like this:</p><pre class="language-matlab">function y = importfiledat(filename, startRow, endRow)
...
fileID = fopen(filename,'rt');
...
y = ...
</pre><p>The <i>importfiledat</i> function works fine when called by itself from the workspace and saves <i>y</i> as a variable there.</p><p>As it stands, running the GUI function shows correctly the popupmenu and pushbutton, but pressing the button results in various errors, an 'fopen error' between them.
I tried calling the <i>importfiledat</i> function from the <i>pushbutton1_Callback</i> function or using <i>assignin</i>, <i>evalin</i> and whatever else I found, with no success.</p><p>Please advise as to how I can pass the information correctly.</p><p>Also, if I then add a plot in the GUI, will I have any problem getting an already drawn plot from the workspace?
The position and characteristics of the GUI objects are changed from the .fig file? Shall I move the popupmenu dir text to that file somehow?</p><p>Is the more basic(?) functionality of normal programming way newbie-friendlier than GUIDE?</p><p>Thank you, D.</p>D Valavanhttps://jp.mathworks.com/matlabcentral/profile/authors/11750287-d-valavantag:jp.mathworks.com,2005:Question/3729572017-12-14T14:25:34Z2017-12-14T14:25:34ZSetting labels and titles of axes extremely slow<p>In my use case the setting of labels and the title of axes takes up to a second or more each and I would like to know why and how I can avoid this.</p><p>My use case is as follows: I have programmatically created a 1300x800 figure using:</p><pre class="language-matlab">mainfig = figure(...
'Units','Pixels',...
'Position',[50 70 1300 80],...
'Name','abc',...
'DockControls','off',...
'Resize','off',...
'NumberTitle','off');
</pre><p>and added about 6~8 custom sized axes to it using:</p><pre class="language-matlab">axes(...
'Parent',mainfig,
'Units','pixels',
'Position',ex [1 2 3 4]);
</pre><p>Creating this window, these axes and the plots that use these axes using:</p><pre class="language-matlab">plot(ax,...)
</pre><p>is fine and takes up next to no time in the profiler.</p><p>However when I add labels and a title to the axes I am seeing up to 1.5 seconds of runtime for each item set. Here is an example from the MATLAB R2015a profiler (problem occurs in <tt>R2015a, R2016b, R2017b</tt>):</p><pre class="language-matlab">Line Code Calls Total Time %Time
48 ax.XLabel.String = 'blablabla... 1 1.412 s 33.3%
50 ax.Title.String = 'blablabla... 1 1.379 s 32.5%
49 ax.YLabel.String = 'blablabla... 1 1.375 s 32.4%
...
</pre><p>The profiler does shows these as 100% self time and does not show the innards of these lines.</p><p>Also, in this case using xlabel() or ax.XLabel.String makes no difference in time cost.</p><p>So, to repeat, I would like to know why and how I can avoid this. It should not be normal that putting a single piece of text somewhere in a GUI costs an eternity of CPU time.</p>JMhttps://jp.mathworks.com/matlabcentral/profile/authors/3209118-jmtag:jp.mathworks.com,2005:Question/3729562017-12-14T14:22:55Z2017-12-14T14:22:55ZHow to calculate the sum of errors for multiple variables?<p>Hello
I have an ODE system which solve temperature and moisture. Let's say temperature is T, and moisture is X, and "num" and "exp" stand for numerical result and experimental value. In the optimization process using "fmincon", I have a function that minimizes the error which is calculated as:</p><pre class="language-matlab">Error=sum(sqrt(T_exp-T_num).^2) + sum(sqrt(X_exp-X_num).^2)
</pre><p>However, I know that the error for temperature could be in orders of 1-5, but my moisture error is in range of 0.0001-.0005. Therefore, the effects of the temperature errors is significantly directing the solution to fit only for temperature. So I get a beautiful fitted temperature, but a skewed moisture profile. So I guess I need to know how to balance the calculated error for multiple variables that vary in totally different ranges. Or I need to use other optimization tools? Any suggestions?</p><p>Thanks</p>Hossein Aminihttps://jp.mathworks.com/matlabcentral/profile/authors/11131988-hossein-aminitag:jp.mathworks.com,2005:Question/2944832016-07-09T08:24:51Z2017-12-14T14:21:38ZGenerate confusion matrix like in classification learner app programmatically<p>The classification learner app provided with the Statistics and Machine Learning Toolbox generates a plot of the confusion matrix with colored cells. Is it possible to generate the same plot programmatically, without passing through the app?
It is very time consuming to always use the app when the number of plots to generate is high.</p>Mustrum Ridcullyhttps://jp.mathworks.com/matlabcentral/profile/authors/7046518-mustrum-ridcullytag:jp.mathworks.com,2005:Question/3729552017-12-14T14:17:29Z2017-12-14T14:17:29ZAdding Random phase causes fft anomalies?<p>Hi</p><p>If I add random_phase to my waveforms then the fft goes skewy - basically it breaks down and is not producing what it should be like when random_phase is not present in sinewave generation loop.</p><pre class="language-matlab">%Setup sampling times and frequency range
f=(20.2 : 0.1 : 21.1)*10^9;
Fs = 3*max(f);
Ts = 1/Fs;
end_t = 0.5*10^-6
dt=0: Ts : end_t -Ts
</pre><pre class="language-matlab">a=0; b=pi; %for random phase calculation
</pre><pre class="language-matlab">%Below part adds a new sine wave every 0.01*10^9 within frequency range
</pre><pre class="language-matlab">for a=1:length(f)-1
random_phase = (b-a).*rand(1,length(dt))+a;
y(a,:) = 5*sin(2*pi.*f(a) .* dt + random_phase); %remove random_phase and scripts works fine.
end
</pre><pre class="language-matlab">%combined waveform
waveform = sum(y);
</pre><pre class="language-matlab">%setup frequency domain for FFT
N=length(waveform);
freq_domain = (0:N-1);
freq_domain = f_domain*Fs/N
</pre><pre class="language-matlab">ft=2*abs(fft(waveform)/N);
</pre><pre class="language-matlab">figure(1)
bar(freq_domain, ft);
ax=gca; ax.XAxis.Exponent = 9;
xlim([20 *10^9 21.4*10^9]);
</pre><p>Completely stumped how random phase messes up my fft...</p>Nathan Kennedyhttps://jp.mathworks.com/matlabcentral/profile/authors/9840909-nathan-kennedytag:jp.mathworks.com,2005:Question/3728462017-12-14T00:15:05Z2017-12-14T14:13:39ZError on filter() - Subscript indices must either be positive integers or logicals<p>I'm trying to use filter() to do a moving average on my data, but I keep getting the error "Subscript indices must either be positive integers or logicals." What's really bothering me is I get the same error when I try running the example on the filter() webpage. Here's the example. It breaks on the y=filter(b,a,x) line.</p><pre> t = linspace(-pi,pi,100);
rng default %initialize random number generator
x = sin(t) + 0.25*rand(size(t));</pre><pre> windowSize = 5;
b = (1/windowSize)*ones(1,windowSize);
b = [1/5 1/5 1/5 1/5 1/5]
a = 1;</pre><pre> y = filter(b,a,x);</pre><pre> plot(t,x)
hold on
plot(t,y)
legend('Input Data','Filtered Data')</pre>Bryan Wilsonhttps://jp.mathworks.com/matlabcentral/profile/authors/8808194-bryan-wilsontag:jp.mathworks.com,2005:Question/1611762014-11-03T17:42:58Z2017-12-14T14:12:26ZConverting Matlab function to mex with user defined class object<p>I need to create a mex file of a function. One of the arguments of the function is the matlab user defined class object. When I try to convert the function to mex, it gives me an error that the function input does not have valid type and user defined class is not supported by coder.type. Is there any solution to this?</p>Amithttps://jp.mathworks.com/matlabcentral/profile/authors/3508731-amittag:jp.mathworks.com,2005:Question/3729492017-12-14T13:48:59Z2017-12-14T14:12:03ZIs there a way to remove or rename a variable in a big mat file?<p>I want to rename/remove a variable but don't want to load and write all the data since it leads to a heavy IO load. Is it possible?</p>Ray Leehttps://jp.mathworks.com/matlabcentral/profile/authors/1411057-ray-leetag:jp.mathworks.com,2005:Question/3729532017-12-14T14:09:20Z2017-12-14T14:09:20ZIntegration and derivation in simulink<p>I want to generate a cos signal in correspondence to a sin signal. My cos signal should have the same amplitude, frequency and similar phase (of course Δφ=90 deg). However after the integration and derivation (dsint/dt= cost or integ(sint)=-cost) I get signals of different amplitude. In the integral case the cos signal also does not range from -1 to 1 but from 0 to -2). In the picture you can see the input signal (upper), the integrated signal (second from the top), the derived signal (3 from the top) and what the expected cos signal should look like (bottom).</p><img src = "/matlabcentral/answers/uploaded_files/98540/Capture.PNG"><p>Also my simulink blocks can be seen. The sin signal has an amplitude of 315, frequency of 100*pi and phase of 0. The cos signal is the same but phase shifted by 90 deg.</p><img src = "/matlabcentral/answers/uploaded_files/98539/Capture.PNG"><p>I am new to simulink and this might be a stupid question but please help :)</p>Nick Vanhttps://jp.mathworks.com/matlabcentral/profile/authors/7385051-nick-vantag:jp.mathworks.com,2005:Question/3728192017-12-13T20:14:36Z2017-12-14T14:04:43ZFunctions reuse in generated code<p>I have a Simulink 2014a model that contains two identical subsystems from a user-defined library. For these subsystems, function packaging parameter is set to reusable. One of the subsystems inputs are fed by constant block, while the other subsystem inputs are fed by gain blocks.
In the generated code (using embedded coder), the functions generated for the two subsystems aren't being reused. When comparing subsystem checksum, I noticed that "ReadsInputInStartFcn" identifier is different between the two subsystems. Note that, I am using a "MATLAB Function (fcn)" block in both subsystems.
Could you please explain the root cause of this difference?</p>Amr Nagatyhttps://jp.mathworks.com/matlabcentral/profile/authors/10262667-amr-nagatytag:jp.mathworks.com,2005:Question/3729422017-12-14T13:11:16Z2017-12-14T14:04:20ZMultiplying matrices and vectors in loop<p>This is the part of the code I want to solve but it gives me error, says that the matrix size are not the same but they are all 3 x 3. Do I need a for loop maybe? Can you help with it?</p><p>clear all, clc; H=1700 %height</p><p>dSG=0.129*H;</p><p>dH=0.185*H;</p><p>dF=0.146*H;</p><p>FiA = -10:20:170 ;</p><p>FiFm = -60:10:170 ;</p><p>FiRm=-60:20:90;</p><p>FiEF=-90:20:60;</p><p>COSA=cosd(FiA);</p><p>SINA=sind(FiA);</p><p>RA = arrayfun( @(sinFif, cosFif) [cosFif 0 sinFif; 0 1 0; -sinFif 0 cosFif], SINA, COSA, 'uniform', 0)</p><p>CA=cell2mat(RA)</p><p>COSE=cosd(FiEF);</p><p>SINE=sind(FiEF);</p><p>RE = arrayfun( @(sinFif, cosFif) [cosFif 0 sinFif; 0 1 0; -sinFif 0 cosFif], SINE, COSE, 'uniform', 0)</p><p>CE=cell2mat(RE)</p><p>[gFiA, gFiFm] = ndgrid(FiA, FiFm);%you want all combinations</p><p>gFiF = gFiFm + gFiA / 3 ;</p><p>COSF = cosd(gFiF); %cosd and sind because you are working in degrees !</p><p>SINF = sind(gFiF );</p><p>RF = arrayfun( @(sinFif, cosFif) [1 0 0; 0 cosFif -sinFif; 0 sinFif cosFif], SINF, COSF, 'uniform', 0)</p><p>CF=cell2mat(RF)</p><p>rSG=[-dSG 0 0]'; %shoulder joint - torso</p><p>rH=[0 0 -dH]' ;% upper arm</p><p>rF=[0 dF 0]';%fore arm</p><p>rW=rSG+CA*CF*rH+CE*rF</p>Tea Arrigonihttps://jp.mathworks.com/matlabcentral/profile/authors/11457302-tea-arrigonitag:jp.mathworks.com,2005:Question/3729522017-12-14T14:01:44Z2017-12-14T14:03:56Z How to rectify this error ?<img src = "/matlabcentral/answers/uploaded_files/98536/Capture.PNG"><p>Math Function 'rem' is supported only in native floating-point mode.</p>Bharadwaj Dungrothhttps://jp.mathworks.com/matlabcentral/profile/authors/9010702-bharadwaj-dungrothtag:jp.mathworks.com,2005:Question/3724732017-12-12T04:37:33Z2017-12-14T13:57:55ZHow to dispaly the value in imshow<p>I make code for inserting elevation value into pixel on contour line</p><img src = "/matlabcentral/answers/uploaded_files/98254/20171212_132537.png"><p>Red line : not inserted</p><p>yellow point : Selected point to insert elevation</p><p>violet line : already inserted<-automatically when I insert elevation into yellow point</p><p>problem is I forget the value easily. So I want to display the value of violet line.
I use imshow to display that image. How can I add displaying value of pixel on that image??</p>Kwanghun Choihttps://jp.mathworks.com/matlabcentral/profile/authors/9864556-kwanghun-choitag:jp.mathworks.com,2005:Question/2579272015-11-28T06:20:36Z2017-12-14T13:54:57ZIs there anyway to convert vibration acceleration data into velocity ?<p>How can I convert the vibration acceleration data collected in real time to velocity ?
I know the relation is to integrate the data but my system requires real time velocity monitoring.
I appreciate your reply.</p><p>Thanks in advance</p>Ellahttps://jp.mathworks.com/matlabcentral/profile/authors/5272704-ellatag:jp.mathworks.com,2005:Question/3729512017-12-14T13:53:06Z2017-12-14T14:01:03ZHow to create density maps from an image?<p>Can anyone guide me how to create color-coded heatmaps (PCD color map) based on the method below? I have been able to create a thresholded binary image (2nd column) and need help in creating the density heat maps based on the method section of the paper:</p><p>"A color-coded perfused capillary density (PCD) map was generated by computing capillary area density within each 16- × 16-pixel sampling window with 8-pixel overlaps over the final binary image (Fig. 1C). This color-coded density map allowed for quick interpretation and better visualization of regional peripapillary capillary density variations across the entire OCT-A image (Fig. 1D). In the color maps, bright red indicates a high density of perfused capillaries, dark blue indicates area of low or no perfused capillaries, and intermediate densities are represented on a spectrum of yellow to green. Larger retinal vessels excluded from the analysis also appear blue on the color maps.""PCD was calculated by the number of pixels associated with perfused capillaries (white pixels) over the (total) number of pixels in the ROI"</p><p>Reference article: <a href = "http://iovs.arvojournals.org/article.aspx?articleid=2570243">link</a></p><img src = "/matlabcentral/answers/uploaded_files/98531/OCTA%20Analysis%20of%20Perfused%20Peripapillary%20Capillaries%20in%20Primary%20Open-Angle%20Glaucoma%20and%20Normal-Tension%20Glaucoma.pdf%20-%20Adobe%20Acrobat%20Pro%20DC.jpg">DKhttps://jp.mathworks.com/matlabcentral/profile/authors/10292157-dktag:jp.mathworks.com,2005:Question/2851772016-05-20T16:34:25Z2017-12-14T13:51:19ZNeed to break down EEG signals into 4 frequency bands<p>Hi all, I'm having a bit of a trouble breaking down an EEG signal into these bands, i dont have a wavelet toolbox, would i need it?</p><pre> theta = 4 - 7.9 Hz
Lower Alpha = 7.9 - 10 Hz
Upper Alpha = 10 - 13 Hz % edited
Lower Beta = 13 - 17.9 Hz
Upper Beta = 18 - 24.9 Hz</pre><p>I have attached the signal EEG recording with this, it has 22 arrays, the eeg channels are from 2 - 15 and the sampling frequency is 128.</p><p>thank you!</p>san chirhttps://jp.mathworks.com/matlabcentral/profile/authors/7817046-san-chirtag:jp.mathworks.com,2005:Question/3729502017-12-14T13:49:33Z2017-12-14T13:49:33ZIn a CDMA context, How to measure network throughput, Packet delibery Ratio and Access Delay? <p>Hello all,</p><p>I am about to simulate a CDMA-based MAC protocol using MATLAB and I have some difficulties to measure the PDR, Throughput and access delay. Have someone already worked on MAC protocol design ?</p><p>Thanking you in advance</p>fairouz benabhttps://jp.mathworks.com/matlabcentral/profile/authors/7502183-fairouz-benabtag:jp.mathworks.com,2005:Question/3727722017-12-13T16:04:47Z2017-12-14T13:43:02ZHow can I pass a TCPIP handle to a parfeval worker<p>In my special case, I need to construct a TCPIP handle before running the parfeval. So I was thinking to pass the TCPIP handle to parfeval. However, it looks like the worker runs under a different workspace than the workspace where TCPIP handle I was constructed. Any idea how to solve this problem ? Thanks</p><p>main code</p><pre> port = tcpip('192.xxx.xx.xx', xxx);
fopen(port);
Request_message = ['aaaaaa'];
fwrite(port, Request_message );
value = [];
parpool(2)
for i = 1:20
f1 = parfeval(@f1_worker,1,port);
if ~isempty(value)
f2 = parfeval(@f2_worker,1,value);
end
[completedIdx,value] = fetchNext([f1]);
end
fclose(port);
delete(port);
delete(gcp('nocreate'));</pre><p>worker</p><pre> function [message] = f1_worker(port)
message = fread(port);
end</pre>Minglei Huanghttps://jp.mathworks.com/matlabcentral/profile/authors/9177609-minglei-huangtag:jp.mathworks.com,2005:Question/3729472017-12-14T13:39:59Z2017-12-14T13:39:59ZHow can I get started with CNN deep learning to image reconstruction?<p>Is it possible to train a CNN and aftwards for a new input gets the output from it?</p>Eduardo Santoshttps://jp.mathworks.com/matlabcentral/profile/authors/8201065-eduardo-santostag:jp.mathworks.com,2005:Question/3729042017-12-14T08:43:24Z2017-12-14T13:39:34Zmultiply the element of a matrix with the element after it.<p>example [2 3 4 5] i want [2*3 3*4 4*5]</p>Hashim Alsaedihttps://jp.mathworks.com/matlabcentral/profile/authors/7592584-hashim-alsaeditag:jp.mathworks.com,2005:Question/3729462017-12-14T13:39:03Z2017-12-14T13:39:03ZHow to produce a DLA Cluster Image<p>I am using Matlab to run a simulation that can produce a DLA/cluster/aggregate image (https://en.wikipedia.org/wiki/File:Of7_p0001_15h.jpg - this sort of image for reference). I started with a random walk where each particle that undergoes the walk starts from a Lattice Boundary and if it come into contact with a 'seed' particle at the centre of the lattice the particle will stop walking and 'attach' itself to the seed. This continues until all the particles have ran and an image with fractal like properties is formed.</p><pre class="language-matlab">for a = 1:N
[x,y,z] = DLARandWalk(n,dt,D,b);
plot3(x,y,z,'--')
hold on
end
</pre><p>DLARandWalk is the walk function per particle (N the number of particles) and the inputs are n, number of steps, dt, change in time per step, D, a diffusion constant that determines step size and b which represents the lattice boundary conditions.</p><p>My question is, what can I use to enable this aggregation? I have tried some logicals, an if loop if the [x,y,z] components match but it hasnt worked. Thanks in advance,</p>Jackhttps://jp.mathworks.com/matlabcentral/profile/authors/5442683-jacktag:jp.mathworks.com,2005:Question/3729442017-12-14T13:22:31Z2017-12-14T13:33:56ZHow can I search for a specific piece of text in a cell array and output the element corresponding to it from a column vector?<p>I've been taught to put columns of data that contain characters into a cell array, and numbers into a column vector.</p><p>The cell array contains names of towns and the column vector contains one piece of data for each one, I'd like to be able to write a towns name and see the output data from the column vector, how do I do this please?</p>Nick Phttps://jp.mathworks.com/matlabcentral/profile/authors/11715658-nick-ptag:jp.mathworks.com,2005:Question/3729452017-12-14T13:32:54Z2017-12-14T13:32:54ZPolarization Losses of 1 Transmitter and Receiver in 3D space<p>I am trying to compute the polarization losses between one half wave dipole transmitter(Tx) and receiver(Rx). Assuming both the Tx and Rx can be rotated at any arbitrary angle different from each other. However I am unable to compute the Azimuth and Elevation angle differences between the Tx and Rx. As I would like to apply this formula P_Loss=cos(azimuth)*cos(elevation). Any idea how I am able to go about solving this? Thanks.</p>Bing Cheng Wonghttps://jp.mathworks.com/matlabcentral/profile/authors/9517749-bing-cheng-wongtag:jp.mathworks.com,2005:Question/3728552017-12-14T02:11:07Z2017-12-14T13:29:45ZHow to aggregate data based on values in a vector?<p>I have matrix A containing 128 columns and m rows. I want to aggregate columns in matrix A based on values in a vector B containing n columns. In the instance that:</p><pre class="language-matlab">A = rand(1000,128);
</pre><pre class="language-matlab">B = [32 45 58 62 73 84 103 112];
</pre><p>I would want to sum columns 1:32 33:45 46:58 59:62 63:73 74:84 85:103 104:112 and 113:128 of matrix A to create a new 1000x9 matrix C. Right now, my code to perform this process is:</p><pre class="language-matlab">C = horzcat(...
sum(A(:,1:B(1)),2),...
sum(A(:,B(1)+1:B(2)),2),...
sum(A(:,B(2)+1:B(3)),2),...
sum(A(:,B(3)+1:B(4)),2),...
sum(A(:,B(4)+1:B(5)),2),...
sum(A(:,B(5)+1:B(6)),2),...
sum(A(:,B(6)+1:B(7)),2),...
sum(A(:,B(7)+1:B(8)),2),...
sum(A(:,B(8)+1:end),2));
</pre><p>I would like to automate this process so that I can change the number of columns in vector B without altering my aggregation code</p><p>Many thanks!</p>Mason Leandrohttps://jp.mathworks.com/matlabcentral/profile/authors/11746439-mason-leandrotag:jp.mathworks.com,2005:Question/3726852017-12-13T08:26:07Z2017-12-14T13:27:52ZLocation pixel and slice<p>Hi everyone.</p><p>Please help me. Now i have 20 slice image PET(dicom format dimension 256x256). How to determine:</p><p>1) The extrat location of pixel value with range 10000-32000 every slice.</p><p>Example: [rows, column, PixelValue]=</p><p>Below is my code to read all the 20 slice:</p><p>first_to_read = 1;
last_to_read = 20;
num_to_read = last_to_read - first_to_read + 1;
for file_idx = 1 : num_to_read
img_number = file_idx + first_to_read - 1;
filename = fullfile('D:\Images PET and CT\PET', sprintf('PET_I1001_PT%03d.dcm', img_number));
X(:, : , 1, file_idx) = dicomread(filename);
end</p><p>Help me..</p>mohd akmal masudhttps://jp.mathworks.com/matlabcentral/profile/authors/10957567-mohd-akmal-masudtag:jp.mathworks.com,2005:Question/971882010-01-28T15:21:00Z2017-12-14T13:23:14ZIs it possible to load my user-defined object into MATLAB without the class definition file?<p>When I remove my class definition file from the MATLAB search path and try to load a saved object of class1, I see the following message:</p><pre> Warning: Variable 'obj' originally saved as a class1 cannot be instantiated as an object</pre><pre> and will be read in as a uint32. </pre><p>I expected unrecognized objects to be loaded as a struct, which was the behaviour in earlier MATLAB versions. This made it very easy to recoup data in the case that the classdef-file was lost (or I end up changing the names of my classes). It also lets other people examine my data without needing my whole software package.</p><p>I see the same behavior if my class definition contains a SAVEOBJ method to save the object as a structure.</p>MathWorks Support Teamhttps://jp.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:jp.mathworks.com,2005:Question/3726972017-12-13T10:03:04Z2017-12-14T13:20:06ZMinMax does not accept 'boolean' signals<p>As the title say, I get this error. Can this be solved somehow or do I need to re-do the model in some other way? This error occurs when trying to do code-generation using the corresponding Simulink version that comes with Matlab 2011b 32-bit.</p>MChttps://jp.mathworks.com/matlabcentral/profile/authors/3768255-mc