http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-12-22T01:26:16Ztag:www.mathworks.com,2005:Question/1673402014-12-20T13:36:22Z2014-12-22T01:26:16ZOptimizing a simple code<p>Hi People</p><p>I trying to optimize the following code and get ride of the for loop. What the code dose, is simple. It estimates the next column in a matrix based on the previous column values times a matrix.</p><pre class="language-matlab">clc
</pre><pre class="language-matlab">clear
</pre><pre class="language-matlab">close all
</pre><pre class="language-matlab">dt=0.01;
</pre><pre class="language-matlab">t=0:dt:10;
</pre><pre class="language-matlab">sls=zeros(2,numel(t));
</pre><pre class="language-matlab">M_c=[0 1;0 0];
</pre><pre class="language-matlab">M_c=M_c+[1 0;0 1]*1/dt;
</pre><pre class="language-matlab">V_s=[0;1];
</pre><pre class="language-matlab">for i=1:numel(t)-1
</pre><pre> sls(:,i+1)=(M_c*sls(:,i)+V_s)*dt;</pre><pre class="language-matlab">end
</pre><p>Any suggestion for a built-in function that would do the for loop part?</p>AJ1/matlabcentral/answers/contributors/3330398-aj1tag:www.mathworks.com,2005:Question/1675092014-12-21T23:28:06Z2014-12-22T00:40:32Zhow to generate a random vector sized 1x100 or 100x1 without the numbers (mod,5)=0 ?<p>vector sized 1x100 or 100x1 without the numbers (mod,5)=0</p>Hüseyin/matlabcentral/answers/contributors/6005952-huseyintag:www.mathworks.com,2005:Question/1673672014-12-20T19:34:56Z2014-12-22T00:40:32ZSimmechanics link the following error message, please advise<p>install_addon('smlink.r2014a.win64.zip')
Installing smlink...
Extracting archive smlink.r2014a.win64.zip to C:\Program Files\MATLAB\R2014a...
Error using install_addon (line 52)
Access is denied.</p>John Valdez/matlabcentral/answers/contributors/5579564-john-valdeztag:www.mathworks.com,2005:Question/1675102014-12-22T00:12:19Z2014-12-22T00:20:06ZHow to concatenate different row size matrices of sequential names through a loop?<p>Let's say I have the matrices:</p><p>-----------------------------------------------------</p><p>a1 =</p><pre> 1 1 1
2 2 2
3 3 3
4 5 6</pre><p>a2 =</p><pre> 5 6 7</pre><p>a3 =</p><pre> 7 7 7
8 8 8
9 9 9
---------------------------------------------------</pre><p>I would like to create a loop using the sequential names from 1 to 3 to produce a final "a" matrix as:</p><p>a =</p><pre> 1 1 1
2 2 2
3 3 3
4 5 6
5 6 7
7 7 7
8 8 8
9 9 9</pre><p>I know that vertcat(a1, a2, a3) would do the job, but I would like to make a loop for cases where the number of sequential variables is large. My main problem is to work with the variable number of rows of each matrix. Any idea would be a huge help for me</p>Edgar/matlabcentral/answers/contributors/5050115-edgartag:www.mathworks.com,2005:Question/1674562014-12-21T12:11:14Z2014-12-21T23:38:20ZCentreline fitting in 3d (3D line fitting)<p>Hello everyone,</p><p>I've got a <b>centreline data set</b> of a vessel and I want to connect the points to get an estimation of the <b>length</b>, however there are a few anomalous points off the main vessel ( i.e. <b>noise</b> ).</p><p>Any thoughts about how to fit the line / remove the points?</p><p>So far I was thinking of using the datatip to manually select unwanted points, but this would obviously take ages. I've tried using "smooth3" to clean up the data, but it didn't do much for me.</p><p>Here's the image below:</p><img src = "/matlabcentral/answers/uploaded_files/22862/untitled.jpg"><p>Cheers,
Will</p>William/matlabcentral/answers/contributors/5011478-williamtag:www.mathworks.com,2005:Question/1675062014-12-21T22:48:19Z2014-12-21T23:33:02ZNeural network input and test input dimension error<p>I try speech recognition with neural network. I am trying to train network with different inputs. For example recognition of number, it has 10 inputs. But when I need to simulate for one input , then matrix dimesion error occurs. My inputs are also vector like [19x156]. So how can ı solve this problem?</p>Onur PEKER/matlabcentral/answers/contributors/4777600-onur-pekertag:www.mathworks.com,2005:Question/1675002014-12-21T21:05:22Z2014-12-21T23:05:27ZHow can I generate a random vector between 1-9 with 10 numbers and at least one number should be >2.<p>X=rand(10,1)*(9-1)+1
How should I change this code to make at least one number >2.</p>Hüseyin/matlabcentral/answers/contributors/6005952-huseyintag:www.mathworks.com,2005:Question/1675082014-12-21T23:03:47Z2014-12-21T23:04:02ZWrite a MATLAB program that prompts the user to enter a Matrix (A) and calculate the - (a) maximum element in each row without using ‘max’ function. (b) maximum element in each column without using ‘max’ function.<p>i have a homework and i cant solve this problem so please help me if anyone know how it solve
Write a MATLAB program that prompts the user to enter a Matrix (A) and
calculate the -
(a) maximum element in each row without using ‘max’ function.
(b) maximum element in each column without using ‘max’ function.</p>abeer/matlabcentral/answers/contributors/6006090-abeertag:www.mathworks.com,2005:Question/1675072014-12-21T23:02:57Z2014-12-21T23:02:57ZSimulate the tossing of a fair coin. Repeat the experiment 1000 and verify that the number of times in which a head appeared is almost 500.<p>i cannot do the loop in this simulation please help</p>mohamed/matlabcentral/answers/contributors/6006087-mohamedtag:www.mathworks.com,2005:Question/1674702014-12-21T13:55:33Z2014-12-21T23:01:23Zhow it is possible to have overfitting before the network learn properly?<p>my question is when my network has a performance about 90 - 98% i mean my learning error is about 98%,(I suppose such performance means my net didn't learn anything yet), how it is possible that my net stops training due to early stopping point?</p>fereshteh/matlabcentral/answers/contributors/5048150-fereshtehtag:www.mathworks.com,2005:Question/1673632014-12-20T19:21:28Z2014-12-21T22:58:37ZHow can you twll within Matlab code when a render is done?<p>This comes up when manually manipulating large surfaces drawn via trisurf.</p><p>It can take several seconds/minutes to redraw the figure after zooming (via the mag pointer) of moving the target point (via the hand pointer).</p><p>Rather than sitting there waiting, and having to remember the previous state to be sure it has changed, it would be helpful to have a way to know when the last render has completed.</p><p>Any hints?</p><p>Thanks</p>Darin/matlabcentral/answers/contributors/5772203-darintag:www.mathworks.com,2005:Question/1673892014-12-20T23:03:34Z2014-12-21T22:54:06ZCombining 6 images without discoloration<p>I tried combining multiple smaller images with a Background.</p><p>In the resulting image the background is just fine, but <b>the smaller images that are added in don't have the right color</b> .</p><img src = "/matlabcentral/answers/uploaded_files/22877/brb%20mich%20erh%C3%A4ngen.JPG"><p>-----</p><p>The desired image looks kind of like this:</p><img src = "http://vignette1.wikia.nocookie.net/pacman/images/e/e7/PacMaze.png/revision/latest?cb=20091031162948"><p>How does one go about solving this problem ?</p><p><b>Edit</b> : All the files have now been attached. I am sorry.</p><p><b>Edit2</b> : Cut everything unrelated to my question out and reuploaded.</p><p>===</p><p>Thank you for your time and consideration .</p>Gino/matlabcentral/answers/contributors/5960871-ginotag:www.mathworks.com,2005:Question/1674752014-12-21T14:50:36Z2014-12-21T22:45:44Zcn anyone tell me in following code wch two wav files are used.?in y1 wad is saved..ds code is for removing unvoiced regions frm speech signal.<p>[y,fs,bt]=wavread('wavfile/do_not.wav');</p><p>[y1,fs,bt]=wavread('wavfile/clipped-do-not.wav');</p><p>y=y./(1.01*abs(max(y)));</p><p>y1=y1./(1.01*abs(max(y1)));</p><p>x=(1:length(y));</p><p>x1=(1:length(y1));</p><p>figure;</p><p>subplot(2,1,1);plot(x,y);</p><p>xtitle('Speech signal waveform for /Do not ask me to walk like that/','Frequency(Hz)','Spectral amplitude (dB)');</p><p>subplot(2,1,2);</p><p>plot(x1,y1);</p><p>xtitle('Speech signal waveform after removing silence region of waveform for /Do not ask me to walk like that/','Frequency(Hz)','Spectral amplitude (dB)');</p>Dhanashri/matlabcentral/answers/contributors/5871906-dhanashritag:www.mathworks.com,2005:Question/1674532014-12-21T11:44:10Z2014-12-21T22:44:03ZCould you inform me that whether it is possible to install Matlab on Windows Server 2012rb?<p>I wish to install matlab on windows server 2012 rb and i was informed that it is not supported. I wish to confirm that before i take alternate path.</p>Ahfaz Ahmed/matlabcentral/answers/contributors/6001840-ahfaz-ahmedtag:www.mathworks.com,2005:Question/1674742014-12-21T14:39:44Z2014-12-21T22:43:04Zws trying ds code ..its nt plotting second plot...my wav file is baby cry signal ...cn anyone help pls?<pre class="language-matlab">[y,fs,bt]=wavread('1.wav');
</pre><pre class="language-matlab">y=y(20001:55000);
</pre><pre class="language-matlab">y=y./(1.01*abs(max(y)));
</pre><pre class="language-matlab">y3=y(19501:20604);
</pre><pre class="language-matlab">ycorr=corr(y3,400);
</pre><pre class="language-matlab">figure;
</pre><pre class="language-matlab">subplot(2,1,1);
</pre><pre class="language-matlab">plot(y3);
</pre><pre class="language-matlab">xtitle('Unvoiced speech segment','time(samples)','amplitude');
</pre><pre class="language-matlab">subplot(2,1,2);
</pre><pre class="language-matlab">plot(ycorr);
</pre><pre class="language-matlab">xtitle('Autocorrelation of unvoiced speech','time(samples)','amplitude');
</pre>Dhanashri/matlabcentral/answers/contributors/5871906-dhanashritag:www.mathworks.com,2005:Question/1673552014-12-20T16:16:48Z2014-12-21T22:39:38ZFunction to find points in pointcloud<p>Hi all</p><p>My issue is that i have a big pointbloud in XYZ coord. Ive got 2 XYZ points, where i need to find all the points in the cloud, which is between this two given points. Does anyone know which kind of funktion i need to use for this? i have tried the find-function, but couldent get it to work.</p><p>thanks in advance.</p>Malte/matlabcentral/answers/contributors/2580384-maltetag:www.mathworks.com,2005:Question/1673592014-12-20T17:34:38Z2014-12-21T22:37:51ZIf-expression only runs the first expression?<p>I created a for loop for a 5x5 matrix (it is a struct with data in it). But there are some values of the matrix I don't want to calculate. For example, I don't want to calculate cell (1,4). I also don't want to calculate the cell (3,4), (4,4),...</p><pre class="language-matlab">if ~((i_testen == 4) & (welke_pp == 1)) | ((i_testen == 4) & (welke_pp == 3)) | ((i_testen == 4) & (welke_pp == 4)) | ((i_testen == 4) & (welke_pp == 5)) %i_testen stands for the measurementnumber. welke_pp stand for the subjectnumber.
</pre><pre class="language-matlab">RASI = data_sts(welke_pp,i_testen).VideoSignals(:, strcmp('RASI', data_sts(welke_pp,i_testen).VideoSignals_headers)); %extract data
XY(2,1) = max(RASI) %maximum of RASI
XY(1,1) = 0; %mimimum is set to zero
Begin_Eind_sts.Begin(i_testen) = abs(XY(2,1)); %store data
Begin_Eind_sts.Eind(i_testen) = abs(XY(1,1));
close all %close all opened figures
else
continue %continue with the previous for-loop
end
</pre><p>The problem is that the program runs perfectly, and even when the values for i_testen = 4 and welke_pp = 1, the program goes to 'else' and continues the for loop. But when the next values for the if-expression comes up (being i_testen = 4 and welke_pp = 3), the program doens't jump to 'else'.</p>Sam/matlabcentral/answers/contributors/5925548-samtag:www.mathworks.com,2005:Question/1675052014-12-21T22:37:35Z2014-12-21T22:37:35ZHow do I install ROS IO package on matlab for mac?<p>Hello,</p><p>I've been using matlab and now I want to try using ROS IO package on matlab R2013a for mac but when I try to install the package I always get the same error messsage. The installation instructions are for a windows computer and even though I try to select the right installation path it says that the path doesn't exist or is not valid and it is not possible to write the path manually.</p><p>Does anyone know how should I access the folowing path on the installation dialog on a mac?</p><p>/Aplications/MATLAB_R2013/toolbox/matlab/general/Contents.m</p>Anna/matlabcentral/answers/contributors/6006054-annatag:www.mathworks.com,2005:Question/1675042014-12-21T22:32:42Z2014-12-21T22:32:42ZParallelization of a Genetic Algorithm (not from the toolbox)<p>I'm writing a parallel Genetic Algorithm in Matlab, specifically a Dual Species Genetic Algorithm (DSGA) (more information can be found <a href = "http://www.idt.mdh.se/kurser/ct3340/ht09/ADMINISTRATION/IRCSE09-submissions/ircse09_submission_23.pdf">in this paper here</a> ), and I'm having some trouble parallelizing part of the code.</p><p>Now I'm a physics and math major and I'm just getting started with my programming to help with my research projects. I've already implemented a serial genetic algorithm in Matlab with a somewhat parallelized fitness function, but I'm interested in implementing this Dual Species Genetic Algorithm.</p><p>Okay so the question: how can i run 2 different for loops that are doing different things on different matlab workers? The 2 for loops will have different data and different code, but I need them to be running simultaneously. I don't think i could use a parfor loop for that. After reading through the documentation for the parallel tool box it looks like using the Single Program Multiple Data (spmd) function may be an option? I'm not really sure if its the best option of it would really work at all.</p><p>Any advice would be appreciated.</p><p>Thanks.</p>Grant/matlabcentral/answers/contributors/5383678-granttag:www.mathworks.com,2005:Question/1674472014-12-21T10:34:07Z2014-12-21T22:31:51ZCut an area in binary Image<p>Hi Everybody,
Please, I would like to cut the white pixels area from a binary image, so that the output will be this white area.
From another question, I see a method that shows how to surround this area, but also I would like to cut automatically the part surrounded, which is a vehicle logo in my case.
Here is the link to this method: <a href = "http://www.mathworks.com/matlabcentral/answers/24041-cut-an-image">http://www.mathworks.com/matlabcentral/answers/24041-cut-an-image</a></p><p>I've tried this method for some hours, and trying to edit it to see the results, but until now I even didnt get the surrounded line, please your help is welcome.</p><p>Thanks!</p><p>Nour.</p>Nour/matlabcentral/answers/contributors/4654548-nourtag:www.mathworks.com,2005:Question/1651462014-12-02T19:08:02Z2014-12-21T22:24:14ZMY PREDICTION DATA IS NOT UPTO DATE AS MY EXPECTATION<p>I have taken population in x and oil price in t. i have taken the year from 1984 to 2014. my work is to find the population and the oil price in the year 2015,2016,2017 or multistep like 2015,2020,2025. i have used the below code and got the result which is not expecting. how the prediction value decreases from 32 onwords while population increases and oil price increases. plz help to solve the problem.
x =</p><pre class="language-matlab">Columns 1 through 6
</pre><pre> [682.5000] [696] [711.7500] [727] [743] [759]</pre><pre class="language-matlab">Columns 7 through 10
</pre><pre> [775.2500] [792.2500] [809.2500] [826.2500]</pre><pre class="language-matlab">Columns 11 through 15
</pre><pre> [843.2500] [860] [877] [896.5000] [914.5000]</pre><pre class="language-matlab">Columns 16 through 19
</pre><pre> [932.5000] [950.5000] [968.7500] [987.5000]</pre><pre class="language-matlab">Columns 20 through 24
</pre><pre> [1.0055e+003] [1.0245e+003] [1044] [1060] [1076]</pre><pre class="language-matlab">Columns 25 through 30
</pre><pre> [1.0935e+003] [1110] [1126] [1142] [1158] [1174]</pre><pre class="language-matlab">Column 31
</pre><pre> [1.1905e+003]
t=</pre><pre class="language-matlab">Columns 1 through 6
</pre><pre> [643] [729] [737] [773] [824] [894.9000]</pre><pre class="language-matlab">Columns 7 through 10
</pre><pre> [947.4400] [987.8500] [1.0838e+003] [1.1498e+003]</pre><pre class="language-matlab">Columns 11 through 14
</pre><pre> [1.1683e+003] [1.1903e+003] [1.2749e+003] [1.3111e+003]</pre><pre class="language-matlab">Columns 15 through 18
</pre><pre> [1.4133e+003] [1.5747e+003] [1.6809e+003] [1.7655e+003]</pre><pre class="language-matlab">Columns 19 through 22
</pre><pre> [1.8444e+003] [2.0313e+003] [2.1274e+003] [2.1887e+003]</pre><pre class="language-matlab">Columns 23 through 26
</pre><pre> [2.2634e+003] [2.3463e+003] [2.4296e+003] [2.5124e+003]</pre><pre class="language-matlab">Columns 27 through 30
</pre><pre> [2.6909e+003] [2.8008e+003] [2.9077e+003] [3.0080e+003]</pre><pre class="language-matlab">Column 31
</pre><pre> [3.1162e+003]</pre><pre class="language-matlab">net = narxnet;
[X,Xi,Ai,T] = preparets(net,x,{},t);
net = train(net,X,T,Xi,Ai);
view(net)
% SIMULATE NETWORK FOR ORIGINAL SERIES
[Y,Xf,Af] = sim(net,X,Xi,Ai);
% CONTINUE SIMULATION FROM FINAL STATES XF & AF WITH ADDITIONAL
% INPUT DATA USING CLOSED LOOP NETWORK.
% Closed Loop Network
netc = closeloop(net);
view(netc)
% 10 More Steps for the first (now only) input
X2 = num2cell(rand(1,10));
% Initial input states for closed loop continuation will be the
% first input's final states.
Xi2 = Xf(1,:);
% Initial 2nd layer states for closed loop contination will be the
% processed second input's final states. Initial 1st layer states
% will be zeros, as they have no delays associated with them.
Ai2 = cell2mat(Xf(2,:));
for i=1:length(net.inputs{1}.processFcns)
fcn = net.inputs{i}.processFcns{i};
settings = net.inputs{i}.processSettings{i};
Ai2 = feval(fcn,'apply',Ai2,settings);
end
Ai2 = mat2cell([zeros(10,2); Ai2],[10 1],ones(1,2));
% Closed loop simulation on X2 continues from open loop state after X.
Y2 = sim(netc,X2,Xi2,Ai2);
plot(1:length(t),cell2mat(t))
hold on
plot(1:length(Y),cell2mat(Y),'r')
plot(length(t):length(t)+length(Y2)-1,cell2mat(Y2),'g')
legend('Input data & target series','One-step ahead prediction','Multi-step prediction beyond target series');
</pre>srikanta mohapatra/matlabcentral/answers/contributors/5511202-srikanta-mohapatratag:www.mathworks.com,2005:Question/1674582014-12-21T12:15:07Z2014-12-21T22:18:42ZStop mutation in GAMULTIOBj<p>Hi,
I tried this simple problem with an initial population. I want to find the best set of combinations of these variables without altering their values. This I'm trying to get by having only crossover children. As I understand from the documentation this can be done by setting crossoverfraction to 1.
But I don't get the expected result.</p><p>e.g.</p><pre> P_s=randi(20,3,9);
numberOfVariables=9;
FitFunc = @multiobjectiveFit;
options = gaoptimset('CrossoverFraction',1,'InitialPopulation',P_s,'CrossoverFcn',@crossovertwopoint)
[x,fval,exitflag]=gamultiobj(FitFunc,numberOfVariables,[],[],[],[],[],[],options);</pre><pre class="language-matlab">function y=multiobjectiveFit(x)
</pre><pre class="language-matlab">y = zeros(2,1);
y(1) =-sum(x);
y(2) =var(x);
</pre><p>gives me a new set of populations x with non-integer values whereas I started with integer values. Please help me. (FYI: My original problem has a very large initial population with non-integer values)</p>Dilini/matlabcentral/answers/contributors/5949685-dilinitag:www.mathworks.com,2005:Question/1674962014-12-21T19:59:01Z2014-12-21T22:17:34ZHow to store all loop results? how can i solve this problem??<p>i have the following loop</p><pre> for i=1:4
for j=2:5
if i<j
a=i;
b=j;
ind=[a,b]
end
end
end</pre><p>how can i store all results for example: a=</p><pre class="language-matlab">1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
</pre>arkedia/matlabcentral/answers/contributors/2436638-arkediatag:www.mathworks.com,2005:Question/1664972014-12-13T12:05:23Z2014-12-21T22:16:23ZCreate a projective homography matrix with pitch/roll/yaw<p>Hi,</p><p>I am working with the imwarp() function where I can put in a picture and a 3x3 projective homography matrix. I got this matrix from the GeometricTransformEstimator but now I want to create such a matrix myself by using a pitch/roll/yaw angle.</p><p>I tried the matlab function angle2dcm(yaw, pitch, roll) which gives me a rotation matrix but it looks like it is not the same as a homography matrix. Is it even possible to do what I want?</p><p>Best Regards</p>Patrick/matlabcentral/answers/contributors/2572769-patricktag:www.mathworks.com,2005:Question/1674412014-12-21T08:41:16Z2014-12-21T22:15:16ZHow to pass a cell to a function?<p>Hello,</p><p>I have a cell array of size (1344X1). each cell element contains a matrix: first row: 22x40 double, second row 22X52 double,, third row 22X112 double, and so on (My data points are all 22-dimentional). Now I want to pass all elements of the cell array at the same time to a function. I tried the following, but it seems to pass the cell emoluments one by one.</p><pre> [centers, membership_idx] = myKmeans(data(:,1));</pre>Negar/matlabcentral/answers/contributors/4405202-negartag:www.mathworks.com,2005:Question/1674382014-12-21T08:03:05Z2014-12-21T22:15:02ZHow to choose the appropriate trained NN?<p>Hi!</p><p>I have divided my data into trn/tst/val sets. The NN gives different classification accuracy at every training session.Should I choose my model simply based on the lowest test set accuracy or should I average the test accuracy over several runs?</p><p>Thanks in advance.</p>TS Sharma/matlabcentral/answers/contributors/5002777-ts-sharmatag:www.mathworks.com,2005:Question/1675032014-12-21T22:14:40Z2014-12-21T22:14:40Zfinding the exact coordinates of the minimum value in a cell array<pre class="language-matlab">mn = cellfun(@(x) min(x(x>0)),A,'Un',0);
[mn,idx] = min(fliplr([mn{:}]));
mn % Show the minimum positve value.
idx = length(A) - idx + 1 % Which cell has the min.
L = cellfun(@(x) find(x==mn),A,'Un',0);
L = L{idx} % And the positions.
</pre><p>I am trying to find the coordinates with the above formula in a cell array 100x61 but each time I get a value that is negative. idx for instance turns negative and this does not help me to locate the coordinates of the minimum value in that cell array. Can anyone help please</p>AA/matlabcentral/answers/contributors/5703029-aatag:www.mathworks.com,2005:Question/1673332014-12-20T11:42:24Z2014-12-21T22:11:27Zgpu array calculation limited memory<p>Hi,
i have a quadro 2200 with 4 gig ram. I would like to do a calculation with a variable that is 6 gigabytes big. Since gpuarray is limited, I wanted to know if there is any other solutiob</p>AA/matlabcentral/answers/contributors/5703029-aatag:www.mathworks.com,2005:Question/1674832014-12-21T16:18:23Z2014-12-21T22:08:07ZHelp with a two variables equation?<img src = "/matlabcentral/answers/uploaded_files/22870/Screenshot_1.png"><p>Hi there,
Im trying to create a 3D graph of the Constant Surface Heat flux in a material.
The equation is in the pic i added.
The thing is, i get problems with multiplying the matrices (x and t)..
What am i doing wrong? is there any one who can help write this code?
Thank you!
(the only variables are x and t, all others are constant.)</p>Nir/matlabcentral/answers/contributors/6005584-nirtag:www.mathworks.com,2005:Question/1673662014-12-20T19:33:21Z2014-12-21T22:07:16ZHow to measure circularity??<p>How to measure circularity ? What is wrong in this code?</p><p>CC=bwconncomp(BW); %BW binary image</p><p>labeled=labelmatrix(CC);</p><p>stats = regionprops(CC, 'all');</p><p>stats.circularity = ((stats.Perimeter) .^2 )./ (4*(pi*(stats.Area)))</p><img src = "/matlabcentral/answers/uploaded_files/22835/im.jpg">rose rose/matlabcentral/answers/contributors/3612391-rose-rosetag:www.mathworks.com,2005:Question/1675022014-12-21T21:36:00Z2014-12-21T21:40:23ZControllerInitialState -> MPC Simulation Options Properties -> Model Predictive Control Toolbox<p>Hello,
Im trying to simulate a nonlinearplant with a linear Model Predictive Controller in MPC toolbox. Im trying to design the controller by simulink and by the command line. I am a new with Matlab/Simulink by the way.
I linearized the plant by myself, and I can simulate it against the nonlinear plant through Simulink and against the linearized plant through command line.</p><p>The problem arises when I want to define the last move of the controller, the initial state of the controller. I dont know how to do it. In the <a href = "www.mathworks.es/help/pdf_doc/mpc/mpc_ref.pdf">Model Predictive Control Toolbox™ Reference</a> it is explained in page 1-92, but when I try to run in my code
options.ControllerInitialState = Ulastmove
being ulastmove the vector with the nominal value (or whatever) of the plant I have the next error:</p><p>"Error using mpc/sim (line 130)
The "ControllerInitialState" property of "mpcsimopt" object must be a valid MPCSTATE object. Type "help mpcstate"
for more information.</p><p>Error in mpc2dcommandlinecleanv2 (line 207)
sim(MPCobj, Tstop, r, options)"</p><p>I dont understand, I tried to create an object called xmpc = mpcstate(MPCobj) as explanied in 1-96 of the reference, but I cant provocate that the last move before simulations is what I define previously.</p><p>Any help is welcome.
I can provide more info if necessary.
Thanks in advance.</p>usermatlabsimulink/matlabcentral/answers/contributors/6000744-usermatlabsimulinktag:www.mathworks.com,2005:Question/1674812014-12-21T15:52:42Z2014-12-21T21:30:20ZPlotting an implicit function?<p>I have the following equation:</p><p>F(x,y) = sqrt( (x^2 * y)^-0.2))</p><p>where x and y are positive.</p><p>The general shape should look like this:</p><img src = "/matlabcentral/answers/uploaded_files/22869/download.png"><p>and I was wondering how I would go about plotting that in matlab, after my unsuccessful attempts with ezplot.</p>J/matlabcentral/answers/contributors/6005504-jtag:www.mathworks.com,2005:Question/1673752014-12-20T20:29:01Z2014-12-21T21:24:16ZHow to convert string to matrix<p>Hi!</p><p>From text file I have read matrix and I got string</p><pre class="language-matlab">A=55 3@ 4 5@ 47 89@ 33 12@
</pre><p>where '@' means it's new row. How will I make matrix from this string to look like this</p><pre class="language-matlab">A =
</pre><pre> 55 3
4 5
47 89
33 12</pre><p>so A is size 4x2 class double</p><p>Please if anyone knows the answer help me</p>delila/matlabcentral/answers/contributors/5918794-delilatag:www.mathworks.com,2005:Question/1672572014-12-19T20:18:39Z2014-12-21T21:23:33ZHow 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/1671382014-12-18T22:40:18Z2014-12-21T21:21:06Zerror 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/1675012014-12-21T21:16:34Z2014-12-21T21:16:34ZHow to make a serial to parallel conversion in simulink?<p>Please help:
If there is an integer number source with : M-ary = 2 and Sampling time Ts = 1e-3 (1 ms).
I want to make a serial to parallel simulink model with the following describtion:</p><img src = "/matlabcentral/answers/uploaded_files/22886/Question.jpg"><pre> Output sequence (1)
Input bits sequence: 1 2 7 8
1 2 3 4 5 6 7 8 9 10 11 12 as shown in figure.
Output sequence (2)
3 4 5 6 9 10 11 12</pre><p>- With the following conditions:
The total sample time of bits (1 2) is 4 ms and total sample time of bits (3 4 5 6 ) is 4 ms too.
and the are out in the same time.</p>Aboashoor/matlabcentral/answers/contributors/2547260-aboashoortag:www.mathworks.com,2005:Question/1674992014-12-21T20:41:36Z2014-12-21T20:57:10ZHow can I get the numbers from a vector? <p>X= rand(50,1)*(100-1)+1
I produced 50 random numbers between 1-100 with this code in a vector.
I want to write the numbers between 45-50 to another vector.</p>Hüseyin/matlabcentral/answers/contributors/6005952-huseyintag:www.mathworks.com,2005:Question/1674612014-12-21T12:38:07Z2014-12-21T20:32:34ZUsing a main GUI window to open new ones<p>I wrote a .fig file's name into button's callback funtion. When I click a button, a new GUI is opening and it's being 2 windows , when I click another button, another GUI is opening , and it's being 3 windows on the screen. But I don't want multiple windows on the screen. I want to use one main window and open my GUIs' on that main window. How can I do that.(By the way I'm creating my GUIs'with GUIDE not with code)</p><p>Thanks in advance.</p>Mahbube/matlabcentral/answers/contributors/5274887-mahbubetag:www.mathworks.com,2005:Question/1672912014-12-20T05:34:39Z2014-12-21T20:22:14ZUnstructured grid to structured grid<p>Dear all,
what would be the best way, in your opinion, to get a structured grid out of an unstructured grid?</p><p>What I have is something like this:</p><pre class="language-matlab">x y f
</pre><pre class="language-matlab">1 12 7
3 10 4
1 11 2
2.4 15 0
</pre><p>So basically x and y are totally random and in no specific order. What I need is to resample the values of f on a structured grid with a constant step.</p><p>I had a quick look at interp2 and it looks like it will only work if my vectors are strictly monotonic which is not the case as I have plenty of repeated values for x and y.</p><p>Thanks a lot</p>Lorenzo/matlabcentral/answers/contributors/1211445-lorenzotag:www.mathworks.com,2005:Question/1646552014-11-28T14:46:00Z2014-12-21T20:09:57ZHow do I get the number of iterations when using the quad(..) function.<p>I am inputing on the Command Window:</p><p>[q, nfun]=quad(@(x) 1/pi*cos(sin(x)), 0,pi)</p><p>nfun seems to give me the number of evaluations for the answer q, but what I need is q for 5 iterations of the gauss quadrature method.</p>Hazra/matlabcentral/answers/contributors/5654733-hazratag:www.mathworks.com,2005:Question/1674952014-12-21T19:53:44Z2014-12-21T19:53:44ZHOW TO EXECUTE THIS APPLICATION OF SPEECH RECOGNITION <p>i have train database and test database</p>imene s/matlabcentral/answers/contributors/5806441-imene-stag:www.mathworks.com,2005:Question/1674942014-12-21T19:50:11Z2014-12-21T19:50:11Zhow to execute this application <p>i have train database and test database</p>imene s/matlabcentral/answers/contributors/5806441-imene-stag:www.mathworks.com,2005:Question/1674932014-12-21T19:07:39Z2014-12-21T19:42:31Zhow to convert discrete to continuous domain using c2d and using for loop for Ts=sampling period<p>how to convert discrete to continuous domain using c2d and using for loop for Ts=sampling period</p>ZZZZZZ/matlabcentral/answers/contributors/6005833-zzzzzztag:www.mathworks.com,2005:Question/1674222014-12-21T05:36:06Z2014-12-21T19:32:34ZMATLAB Certified Associate/Professional<p>Do we have any here? Just curious. It has been a while since it was released and I am wondering if any of the most esteemed contributors to MathWorks Answers have these certifications.</p>John/matlabcentral/answers/contributors/5415607-johntag:www.mathworks.com,2005:Question/1649302014-12-01T12:42:17Z2014-12-21T19:24:01Zvolume enclosed by isosurface<p>How can I calculate the volume enclosed by an isosurface, in this case my isosufaces are generally irregular cylinders.</p><p>I've attached an image to give you and idea of the tubes (although its not a great one!)</p><img src = "/matlabcentral/answers/uploaded_files/21941/cleaner.png"><p>Convex hull method over estimates due to its curvature, but could possibly work for small segments and summation over the whole tube. However, there must be a simpler way!?</p><p>Many thanks, Will</p>William/matlabcentral/answers/contributors/5011478-williamtag:www.mathworks.com,2005:Question/1674462014-12-21T10:08:44Z2014-12-21T19:17:57ZCode genaration - function reuse with different variables size<p>Hi,</p><p>I have 2 matlab coder projects and I wish to use the same function in both of them (the exact one, not a duplicate).</p><p>Let's say, for example, that my function looks like that:</p><pre class="language-matlab">function a = Foo
a = randn(SIZE_OF_VAR);
</pre><p>where 'SIZE_OF_VAR' is some constant.</p><p>In Project A, 'Foo' is one of many entry point functions. In Project B, 'Foo' is only called from other function and is not required to be an entry point function.</p><p>My problem is that 'SIZE_OF_VAR' must be different in Project A and Project B. I know that in Project B I can pass it as an input argument. But in Project A it should be hard coded, as far as I know (variable sizing and dynamic memory allocation are not an option).</p><p>Is there anyway that it can be achieved?</p>Y/matlabcentral/answers/contributors/3443044-ytag:www.mathworks.com,2005:Question/1674922014-12-21T18:40:15Z2014-12-21T19:15:47ZSimulate circular sound using earphones<p>Hi Matlab people!!!
I'm trying to simulate a circular sound using earphones, something like this...
First I hear a sound in my left ear, after that I hear it over my head, after that I hear it in my right ear and finally near my mouth. It's this possible using Matlab ?
Help me please</p><img src = "/matlabcentral/answers/uploaded_files/22875/Earphones.jpg">Mario/matlabcentral/answers/contributors/5666279-mariotag:www.mathworks.com,2005:Question/1674852014-12-21T17:26:02Z2014-12-21T19:08:08ZHow to make 'solve' work?<p>Hello, I have just recently started using Matlab and are still learning the basics. I have tried to solve an equation but the 'solve' tool does not seem to work for me. I've put in the following:</p><pre class="language-matlab">solve(cos(x/50)-1/sqrt(2)==10^-3, x)
</pre><p>And it gives me the error: Undefined function or variable 'x'. How am I meant to make it work?</p>Marcus/matlabcentral/answers/contributors/5855970-marcustag:www.mathworks.com,2005:Question/1674482014-12-21T10:51:37Z2014-12-21T18:53:22ZHow to find the intersection polyhedron of two bigger polyhedra?<p>I used <i>convhulln</i> to get the vertices of these two polyhedra, now I try to get a new convex polyhedron which is the intersection of two bigger polyhedra, and <b>its vertices</b> .</p><p>Is there any tips for solving this problem? Thanks a lot.</p>Qiu/matlabcentral/answers/contributors/6005141-qiutag:www.mathworks.com,2005:Question/1673882014-12-20T22:24:03Z2014-12-21T18:45:14ZHello, I have a problem when I try to assign numeric arrows to string elements of a vector<p>Let's say I want something simple as this:</p><p>>> B=rand(3,3)</p><p>B =</p><pre> 0.9971 0.5053 0.4919
0.6846 0.9699 0.8862
0.8670 0.8364 0.7298</pre><p>>>for i=1:3</p><pre> A(i,:) = cellstr(sprintf('A%d',i))</pre><pre> end</pre><p>>> A</p><p>A =</p><pre> 'A1'
'A2'
'A3'
'</pre><p>But now I want assign each arrow of the B matrix to each element of the A vector such that I get:</p><p>A1= [ 0.9971, 0.5053, 0.4919 ]</p><p>A2= [ 0.6846, 0.9699, 0.8862 ]</p><p>A3= [ 0.8670, 0.8364, 0.7298 ]</p><p>What's the best way to do that? It might be piece of cake for many of you but still I am struggling with this a lot.</p><p>I tried using:</p><p>>> for j=1:length(A)</p><pre> A{j}=B(j,:)</pre><pre> end</pre><p>But in the end I get:</p><p>A =</p><pre> [1x3 double]
[1x3 double]
[1x3 double]</pre><p>Which is not what I expected.
Please I would appreciate some help</p>Edgar/matlabcentral/answers/contributors/5050115-edgar