https://se.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-09-22T06:19:20Ztag:se.mathworks.com,2005:Question/3578532017-09-22T06:19:20Z2017-09-22T06:19:20ZFind value in cell array and return index<p>Hello</p><p>I have a cell array of the form:
<i>A={[1,2,3;4,5,6],[11,22],[33;55;66;7]};</i>
Now I want the code to return the index of e.g. value "5",
i.e. <i>A{:,1}(2,2).</i>
How do I write this?</p><p>Thank you for any help
LF</p>LittlFrenhttps://se.mathworks.com/matlabcentral/profile/authors/9480891-littlfrentag:se.mathworks.com,2005:Question/3578522017-09-22T06:15:08Z2017-09-22T06:15:08ZHow can I make MATLAB open .m files on the same window that is currently open (open as a new tab next to the current tab)?<p>I recently received a computer from our department and tried to open .m files. (R2017a)
Whenever I double-clicked them, they opened in new windows. But these new windows do not include the new .m files that I tried to open; they still had the old tabs that were open already.
I also tried to drag and drop .m files to MATLAB window that was open and it didn't let me open them, showing me a circle mouse icon with a cross in it.
My labtop has the same version of MATLAB (R2017a) and the things I mentioned above do not happen at all.
Can anybody help me with this issue?</p>SOO BUM BAEhttps://se.mathworks.com/matlabcentral/profile/authors/8921348-soo-bum-baetag:se.mathworks.com,2005:Question/3578052017-09-21T20:40:36Z2017-09-22T06:08:13ZMLP classification: what is the problem in my code?<p>I would like to understand why the neural network with MLP I built works badly.
The network should be a universal classifier because it has two hidden layers but, with the data set I use, my neural network does not train well.
My network is built using</p><ol><li>in the first and second layers a sigmoidal transfer function</li><li>in the output layer a soft max function
"inputs" file is a 3x120 matrix: 3 features and 120 observations
" targets" file is a 3x120 matrix (representative of 3 different classes).</li></ol><p>In the example code I used a network with 40 neurons in the first layer and 20 in the second layer.</p><p>I notice two anomalies</p><ol><li>if I perform <i>view (net)</i> I see that the number of outputs of the output layer is 2 while the output box is 3: what does this mean and why Matlab does this?</li><li>in the output layer a soft max function
If I do <i>sum (net ([i1;i2; i3])</i> I have a value different from 1 but it should be 1 because in the last layer there is a softmax function.</li></ol><p>In the following I write my code while I attach <i>inputs</i> and <i>outputs</i> file</p><pre> Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainbr'; % Scaled conjugate gradient backpropagation.</pre><pre class="language-matlab">% Create a Pattern Recognition Network
hiddenLayerSize = [40 20];
</pre><pre class="language-matlab">net=feedforwardnet(hiddenLayerSize);%crea rete feedforward
%imposta funzione trasferimento
</pre><pre class="language-matlab">net.layers{1}.transferFcn = 'tansig'
net.layers{2}.transferFcn = 'tansig'
net.layers{3}.transferFcn = 'softmax'
</pre><pre class="language-matlab">% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
</pre><pre class="language-matlab">% Train the Network
[net,tr] = train(net,x,t);
</pre><pre class="language-matlab">% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
</pre><pre class="language-matlab">% View the Network
view(net)
</pre><pre class="language-matlab">% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
figure, plotconfusion(t,y)
%figure, plotroc(t,y)
</pre><img src = "/matlabcentral/answers/uploaded_files/88662/net.png">mike mikehttps://se.mathworks.com/matlabcentral/profile/authors/6530568-mike-miketag:se.mathworks.com,2005:Question/3578512017-09-22T06:02:43Z2017-09-22T06:02:43ZIndex exceeds matrix dimensions. Error in fcmclust (line 40) plot([toda(:,x) collosal(:,x) illexblck(:,x) backlightblck(:,x) loligoblck(:,x)],... <p>Matlab “Index exceeds matrix dimensions.”</p>hima binduhttps://se.mathworks.com/matlabcentral/profile/authors/9005125-hima-bindutag:se.mathworks.com,2005:Question/2198032015-05-27T22:00:37Z2017-09-22T05:57:58ZHow To Smooth The Image Edge<p><<</p><img src = "/matlabcentral/answers/uploaded_files/31654/hand_edge.png"><p>>>i use :
image=imread('hand.png');
e=edge(image,'canny');
imshow(e);</p>behnam emamihttps://se.mathworks.com/matlabcentral/profile/authors/6465213-behnam-emamitag:se.mathworks.com,2005:Question/2506812015-10-23T20:08:23Z2017-09-22T05:56:29ZSpeedgoat Driver and Tools (xPC Target) installation problem<p>Hey guys,</p><p>I´m a mechatronic student. For a study project i need to implement the Speedgoat Libary in Matlab. I work with the R2014b Version.</p><p>I followed the following installation guide: <a href = "https://www.speedgoat.ch/Resources/Support/TargetMachineSetup/index.html?software_installation_gen.htm">Speedgoat - Installation Guide</a></p><p>Well, I start the installation with running the speedgoat_setup.p, but i get the following error message:</p><p>Failed to create log file.
Undefined function or variable 'xpcroot'.</p><p>Error in speedgoat_setup (line 171)</p><p>Get anyone the same error and have a solution for this problem?
I hope you can help me =)</p><p>Best regards
Matthias</p>Matthias Bolsingerhttps://se.mathworks.com/matlabcentral/profile/authors/7113237-matthias-bolsingertag:se.mathworks.com,2005:Question/3578332017-09-22T02:34:34Z2017-09-22T05:55:38Zparticle swarm optimization - Error too many input arguments - reg<p>i am doing a linear programming problem involving large number of variables . i ran the problem with genetic algorithm and simulated annealing algorithm in MATLAB and got the results. I ran linear programming (linprog) also and got the results. Now i want to run this problem with particle swarm optimization. i entered the following lines.</p><p>options = optimoptions('pso');
options.Display = 'iter';
nvars = 1728;
lb = zeros(1,1728);
x = pso(fun,nvars,Aineq3,Bineq3,lb,options);</p><p>But the MATLAB is showing the error message .</p><p>Too many input arguments.</p><p>How can i correct my code.</p><p>Also, suppose if i want to apply the results obtained from genetic algorithm as the initial population for the particle swarm optimization algorithm, what corrections i have to make in my code.</p>Mechanical Engineeringhttps://se.mathworks.com/matlabcentral/profile/authors/5909596-mechanical-engineeringtag:se.mathworks.com,2005:Question/3578032017-09-21T20:30:06Z2017-09-22T05:52:06ZHow to make this integral<p>Hi
Suppose we have following equation:</p><p>S(x,t) = p(x,t) + k * int_0^t h(\tau) d\tau.</p><p>What is the difference between this and
S(x,t) = p(x,t) + k * int_0^t h(t) dt ?</p><p>How ould the simulink block differs? I appritiate any help. Thank you</p>Maahttps://se.mathworks.com/matlabcentral/profile/authors/2004384-maatag:se.mathworks.com,2005:Question/3578502017-09-22T05:50:09Z2017-09-22T05:50:09ZHow I find rows with same elements but in flipped manner.<p>Hi,
I have a matrix suppose A=[1 2;3 4;2 1; 5 3;4 3];
I need to detect row 1 and 3 as well as row 2 and 5 as unique row. my final matrix should be like
A=[1 2;3 4;5 3];</p><p>Thank you in Advance</p>Raj Kishorhttps://se.mathworks.com/matlabcentral/profile/authors/9409974-raj-kishortag:se.mathworks.com,2005:Question/3578432017-09-22T04:08:55Z2017-09-22T05:47:38ZHow can I control the precision of the output?<p>Most often, the scenarios about accuracy I met are that I can't declaim that a figure, which theoretically is zero while numerically is not zero, equals to zero, which impede the following process.</p><p>For example, after applying an algorithm that transform a matrix to a upper triangular matrix, I want to determine if the left bottom entries are equal to zero. But some of them are -7.1779e-16, or 1.6653e-16, which theoretically should be zero. So how can I change the precision to transfer these ignorable figures to zero?</p>Jing Zenghttps://se.mathworks.com/matlabcentral/profile/authors/10782778-jing-zengtag:se.mathworks.com,2005:Question/990672013-03-05T15:36:00Z2017-09-22T05:36:36ZWhy do I receive License Manager Error -9?<p>When I try to launch MATLAB, I get the following error:</p><p> </p><pre class="error"> License checkout failed. Invalid host. License Manager Error -9</pre>MathWorks Support Teamhttps://se.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:se.mathworks.com,2005:Question/3578492017-09-22T05:28:49Z2017-09-22T05:30:36ZHow can I plot the discrete signal y(n) with input x(n) by using matlab command stem?<p>n=4:1:6;</p><p>x(n)=log2(n+1);</p><p>y=(x(n)+x(n-1)+x(n-2)+x(n-3))/4;</p><p>stem(n,y)</p>Po Hsiang Wuhttps://se.mathworks.com/matlabcentral/profile/authors/10624663-po-hsiang-wutag:se.mathworks.com,2005:Question/3578252017-09-22T00:28:28Z2017-09-22T05:24:59ZHey guys , How can i shift rows or columns within an array?<p>A = [ 1,2,3;4,5,6;7,8,9]
How do i shift [1 , 2 , 3] to where [ 4,5,6] is?</p>Prashikh Agrawalhttps://se.mathworks.com/matlabcentral/profile/authors/10354577-prashikh-agrawaltag:se.mathworks.com,2005:Question/3578482017-09-22T05:07:19Z2017-09-22T05:23:19Zwhy robotics.OccupancyGrid is not supporting for code generation?<img src = "/matlabcentral/answers/uploaded_files/88680/prm_codegen_error.PNG"><p>I have Matlab Coder and Robotics Toolbox license. When i try to generate C code from the PRM Robotics M-Script, The robotics.OccupancyGrid is not supporting for code generation. It throws an error "Function call failed". Kindly support on this</p>Anu Manihttps://se.mathworks.com/matlabcentral/profile/authors/11025720-anu-manitag:se.mathworks.com,2005:Question/3577062017-09-21T09:54:35Z2017-09-22T05:15:06Zhow to plot these different plots into one by merging the plots and see the difference ,how far its tilted?<p>Hereby I had attached the figure ,kindly suggest how to combine these plots by overlapping each other to see the difference that how far its titled</p>INDU MAHESWARIhttps://se.mathworks.com/matlabcentral/profile/authors/10734318-indu-maheswaritag:se.mathworks.com,2005:Question/3569432017-09-16T06:09:27Z2017-09-22T05:06:42ZHow to fit a curve using "power" fitting or "custom fitting"?<p>I have data which I need to fit using following equation:</p><p>y= f(x)= a*x^b+c.</p><p>Code:</p><p>r=scatter(npp7,lk_2k1);</p><p>r.MarkerEdgeColor = 'r';</p><p>r.MarkerFaceColor = [0.9 0.9 0.9];</p><p>hold on</p><p>% Power fit - %y=f(x)=a*x^b+c</p><p>a=28.54;</p><p>b=0.4634</p><p>c=-3.289;</p><p>x = data(:);</p><p>y = a*x^b+c;</p><p>%f = fit(x,y);</p><p>p = plot(x,y)</p><p>p(1).LineWidth = 2;</p><p>c = p.Color;</p><p>p.Color = 'r';</p><p>It shows:
Error using ^
One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.</p><p>But if I use(.^), it shows multiple fit lines as shown in attached figure. I want just one fit line for same equation.</p>ishita agrawalhttps://se.mathworks.com/matlabcentral/profile/authors/3342911-ishita-agrawaltag:se.mathworks.com,2005:Question/3557822017-09-08T04:00:00Z2017-09-22T05:02:14ZWhy do I encounter a "Error while downloading third party files" when installing a Support package In R2017b?<p>Why do I encounter a "Error while downloading third party files" when installing a Support package In R2017b?</p>MathWorks Support Teamhttps://se.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:se.mathworks.com,2005:Question/3577272017-09-21T12:15:12Z2017-09-22T04:49:27Zpoissrnd function issue: weird histogram<p>I tried to produce 10^6 poisson distributed random numbers and when i looked at the histogram, it had either some gaps or shoots depending upon the bin size... can anyone exlpain whats happening here?</p><pre> t = zeros(1000000,1);</pre><pre> for i = 1:1000000
t(i,1) = poissrnd(100);
end</pre><pre> hist(t,300)</pre><img src = "/matlabcentral/answers/uploaded_files/88626/askmatlab.PNG">Saurabh Talelehttps://se.mathworks.com/matlabcentral/profile/authors/10803246-saurabh-taleletag:se.mathworks.com,2005:Question/3578472017-09-22T04:47:03Z2017-09-22T04:48:01ZHow can I interpret this plot in the output of SimBiology?<p>I constructed the compartment model, fitted the data and got the output but one of the output that I am not clearly understand is the plot between predicted concentration and observed concentration that I want to know how I can interpret this plot. And what is the Y-axis?</p><img src = "/matlabcentral/answers/uploaded_files/88679/fig6.jpg">Chayaporn Sathitihttps://se.mathworks.com/matlabcentral/profile/authors/10382038-chayaporn-sathititag:se.mathworks.com,2005:Question/3578462017-09-22T04:34:43Z2017-09-22T04:34:43Zresize objects inside matlab gui created with guide<p>Hi,</p><p>I've created a gui using guide where user uploads the files using pushbutton and another list box to display variables inside the files, an axes to display the chart and few more pushbuttons and list boxes for exporting options. Now the axes occupies half the size of figure. If the user after uploading the file to gui, wants to reszie the plot to make the plot bigger, how to give a resizable behaviour to each objects inside gui? I want an options like drag and reduce the size of all the buttons inside a panel.If it is possible only in programmatic way,then how to attain a drag icon when the mouse pointer comes near to the border of a panel?</p>sureyhttps://se.mathworks.com/matlabcentral/profile/authors/8483409-sureytag:se.mathworks.com,2005:Question/3578452017-09-22T04:25:35Z2017-09-22T04:32:12ZHow can I combine two existing figures in one?<p>Hello all,
I have two figures with a surface plotted in each one.The figures have the same axes, titles,.... How can I have these two together in one figure?</p>Nilouhttps://se.mathworks.com/matlabcentral/profile/authors/7639988-niloutag:se.mathworks.com,2005:Question/3578382017-09-22T03:37:32Z2017-09-22T04:31:49ZHow to create matrix in MATLAB from an array?<p>How to create a matrix quickly, for example, from a consecutive sequence, like what R does?</p><pre class="language-matlab">matrix(1:12, 3, 4)
</pre><p>It seems doltish to input all the entries one-by-one.</p>Jing Zenghttps://se.mathworks.com/matlabcentral/profile/authors/10782778-jing-zengtag:se.mathworks.com,2005:Question/3578442017-09-22T04:18:46Z2017-09-22T04:19:39Zhow to increase CPU usage when use bicgstab?<p>I am using bicgstab to solve a large system of linear equations. however, only 2 cores work out of 4 on my desktop; and when I do my calculation on supercomputer, only around 4~5 cores work out of 64 cores. How do I increase my CPU usage?</p>yulai zhanghttps://se.mathworks.com/matlabcentral/profile/authors/8077506-yulai-zhangtag:se.mathworks.com,2005:Question/3578422017-09-22T04:03:43Z2017-09-22T04:03:43ZWhy do get Fatal Startup Error when launching Matlab?<p>Whenever I launch Matlab, a small window will appear which says Initialization Error with the heading: Fatal Error on Startup. The Matlab programe open as normal but the window stays. And when i close the window, the Matlab programe will close too. Can anyone tell me how to solve this problem?
Thank you!</p>So Jia Yihttps://se.mathworks.com/matlabcentral/profile/authors/10859169-so-jia-yitag:se.mathworks.com,2005:Question/3578322017-09-22T01:46:12Z2017-09-22T03:55:57ZColumn mismatch error in pdist2 even though i am passing two arrays with same no of columns<p>I have passed two arrays filterResponses and dictionary having 60 columns each to pdist 2 It still shows an error of column mismatch.
The output is as follows:</p><pre class="language-matlab">Converting to visual words tennis_court/sun_dzlhnmruizdpszex.jpg
</pre><pre class="language-matlab">filterResponse_size =
149000 60
</pre><pre> dictionary =
2 60</pre><pre class="language-matlab">Error using pdist2 (line 142)
X and Y must have the same number of columns.
</pre><pre class="language-matlab">Error in getVisualWords (line 17)
dist = pdist2(filterResponses, dictionary, 'euclidean');
</pre><pre class="language-matlab">Error in batchToVisualWords (line 51)
parfor i=1:l
</pre>smruti venkateshhttps://se.mathworks.com/matlabcentral/profile/authors/10852425-smruti-venkateshtag:se.mathworks.com,2005:Question/3578412017-09-22T03:52:38Z2017-09-22T03:56:16ZUsing Newton-Raphson and Bisection method to solve a Nonlinear Equation<p>Using Newton-Raphson and Bisection method to estimate the root of</p><p>f(x) = x^3 - x - 2</p><p>employing an initial guess of x0 = 0</p><p><a href = "http://www.upsieutoc.com/image/TPayhj">http://www.upsieutoc.com/image/TPayhj</a></p><p>Many thanks!</p>Ninh Ghosterhttps://se.mathworks.com/matlabcentral/profile/authors/9409792-ninh-ghostertag:se.mathworks.com,2005:Question/3578402017-09-22T03:47:23Z2017-09-22T03:47:23ZWhile opening polyspace result i'm getting error as below snaphot, please suggest solution.<p>Not: The polyspace project file(.psprj) created by script.</p>Sankethttps://se.mathworks.com/matlabcentral/profile/authors/8386501-sankettag:se.mathworks.com,2005:Question/3578392017-09-22T03:38:00Z2017-09-22T03:38:00ZMake faces of cube transparent<p>Hello,</p><p>I have made a 3D cube but would like to have the faces appear transparent. How do I go about doing that? Thanks.</p><p>Here is my code:</p><pre class="language-matlab">vert = [0 0 0;1 0 0;1 1 0;0 1 0;0 0 1;1 0 1;1 1 1;0 1 1];
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat')
</pre><pre class="language-matlab">view(3)
axis vis3d
rotate3d
xlabel('x')
ylabel('y')
zlabel('z')
</pre>monkey_matlabhttps://se.mathworks.com/matlabcentral/profile/authors/1029105-monkey_matlabtag:se.mathworks.com,2005:Question/3578372017-09-22T03:28:47Z2017-09-22T03:30:51Zhow to update a data in the simulink matlabfcn<p>In simulink,I want to realize this goal:I use a microphone to coolect a signal, then input it into a matlab fcn .In the fcn,I want to operate with it to produce a 'y'.The data 'y' will be used to affect the matlab fcn the next time.Also , In the first time ,I must initialize the 'y',such as"y=zeros(a,b)"
But!!!!,I dont want to initialize the 'y'in the next operation .In the next time ,The'y' is the last'y'.
I mean every operation update 'y',and use it the following time.how can I get it?becaus it do this function from begining to the end ,so it not aviod to initialize'y'</p>yu xin lihttps://se.mathworks.com/matlabcentral/profile/authors/8824223-yu-xin-litag:se.mathworks.com,2005:Question/3578362017-09-22T03:25:41Z2017-09-22T03:26:42ZWhy polyspace is is taking time to upload project to remote server?<p>Why polyspace is is taking time to upload project to remote server? Even though project is small in size, it is taking more than 30 minutes.</p>Sankethttps://se.mathworks.com/matlabcentral/profile/authors/8386501-sankettag:se.mathworks.com,2005:Question/3578352017-09-22T03:21:29Z2017-09-22T03:21:29ZDoes anyone have an implementation of an algorithm to detect atrial fibrillation?<p>Are there articles that have the detection algorithm, but has anyone implemented it already? Could you pass the code?</p>mtmhttps://se.mathworks.com/matlabcentral/profile/authors/11036132-mtmtag:se.mathworks.com,2005:Question/3578342017-09-22T03:05:48Z2017-09-22T03:05:48ZExtract each pixel of an image<p>Hello All,</p><p>A quick question and I believe it will be fairly easy as well but being new I am stuck in some fundamentals and this forum is helping me to move forward.</p><p>Problem: I wrote a code which is stacking 1024 images of 640x512 resolution in a 3D matrix. And wrote few loops which is extracting the appropriate image from 1024 if needed and 2. Cutting the stack of images in row and column in next two loops as needed.</p><p>Question: Now I would like to read each pixel of the image one by one such that (:,1,1) will correspond to the first row and give me the values for that. But I want to create a for loop which is capable of reading each pixel of each image. How can I create a loop for that?
I have attached the code I am working with.</p><p>Please advice.
Thanks</p>Rahul Thakurhttps://se.mathworks.com/matlabcentral/profile/authors/5757086-rahul-thakurtag:se.mathworks.com,2005:Question/3576742017-09-21T05:52:25Z2017-09-22T02:59:44Z3 Errors involving linespace and multiplication symbol<p>Trying to code a projectiles motion from start to when it hits y=0. All the numbers/data is in. Part of the assignment is to create user-defined inputs as you'll see in the code. Problem
i'm having is without any of the user inputs, the code runs fine. Once I insert user defined inputs, I get 3 errors.</p><p>The errors are:</p><pre class="language-matlab">Error using .*
</pre><pre class="language-matlab">Matrix dimensions must agree.
</pre><pre class="language-matlab">Error in linspace (line 30)
y = d1 + (0:n1).*(d2 - d1)/n1;
</pre><pre class="language-matlab">Error in DummyCode (line 22)
t = linspace(0, tend, 1000);
</pre><p>I made a dummy file that's the exact same code as my assignment just without my comments,has the same errors, here it is:</p><pre class="language-matlab">a = input('45');
</pre><pre class="language-matlab">b = input('0');
</pre><pre class="language-matlab">c = input('0');
</pre><pre class="language-matlab">d = input('90');
</pre><pre class="language-matlab">Angle_deg = d;
</pre><pre class="language-matlab">Angle_rad = Angle_deg * pi/180;
</pre><pre class="language-matlab">V0 = a;
</pre><pre class="language-matlab">Vox = V0 * cos(Angle_rad);
</pre><pre class="language-matlab">Voy = V0 * sin(Angle_rad);
</pre><pre class="language-matlab">Y0 = c;
</pre><pre class="language-matlab">X0 = b;
</pre><pre class="language-matlab">g = -9.81;
</pre><pre class="language-matlab">ax = 0;
</pre><pre class="language-matlab">ay = g;
</pre><pre class="language-matlab">tend = (-Voy - sqrt(Voy^2 - 4.*(.5.*ay).*Y0))/(2 .*((.5).*ay));
</pre><pre class="language-matlab">size(tend);
</pre><pre class="language-matlab">t = linspace(0, tend, 1000);
</pre><pre class="language-matlab">x = X0 + V0*t + .5 * ax * t.^2;
</pre><pre class="language-matlab">y = Y0 + V0*t + .5 * ay * t.^2;
</pre><pre class="language-matlab">plot(x,y)
</pre>Moehttps://se.mathworks.com/matlabcentral/profile/authors/11027118-moetag:se.mathworks.com,2005:Question/3575612017-09-20T13:35:15Z2017-09-22T02:59:17ZMy matlab gets an error when trying to plot anything<p>As the title says, this only happened recently and I'm not sure what triggered it.</p><p>I'm using Windows 64.
This comes up every time I plot something:</p><p>Error using gca
Can't load 'C:\Program
Files\MATLAB\R2017a\bin\win64\osgserver.dll': C:\Program
Files\MATLAB\R2017a\bin\win64\osgserver.dll is not a valid
Win32 application.</p>Ye Chenhttps://se.mathworks.com/matlabcentral/profile/authors/10788943-ye-chentag:se.mathworks.com,2005:Question/3577962017-09-21T19:58:26Z2017-09-22T02:49:56ZHow can i extract green rectangle area from the rgb image ?<p>I have two image. one i take in night and another take in daylight. So i only mask the region where green pixels exists. but problem is that for every image i need to change the value. how can i fix it the same value for all images.</p><pre class="language-matlab">Im = imread('4.jpg');
figure,imshow(Im);
</pre><pre class="language-matlab">lab = rgb2lab(Im);
figure,imshow(Im);
</pre><pre class="language-matlab">% Im = imresize(Im, [512 512]);
% figure,imshow(lab(:,:,2));
</pre><pre> I1=lab(:,:,2);
I2=lab(:,:,3);
I3=lab(:,:,1);</pre><pre> mask1=I1>-50 & I1<0 ;
mask2=I2>30 & I2<50;</pre><pre> mask =I3 & mask1 & mask2;</pre><pre class="language-matlab">% mask=mask1 ;
</pre><pre> figure,imshow(mask);</pre><pre> diff_im = im2bw(mask,0.18);
figure,imshow(diff_im);</pre><img src = "/matlabcentral/answers/uploaded_files/88656/2.jpg"><img src = "/matlabcentral/answers/uploaded_files/88657/4.jpg">sufian ahmedhttps://se.mathworks.com/matlabcentral/profile/authors/10225144-sufian-ahmedtag:se.mathworks.com,2005:Question/3578062017-09-21T21:11:25Z2017-09-22T02:48:53ZChoosing the 3 closest points<p>Hi!</p><p>I am doing some simple machine learning(kNN classifier), and are having trouble with picking the three nearest points of each point I want to classify. I want the find the three 'tp's that are closest to each of the 'x's and add them to the 3x1 matrix 'cp'. I feel like I am on to something, but it's not the closest that are being chosen. In the last piece of the code, you're able to compare the points that is chosen to all the points, it's pretty easy to see if the closest is chosen.</p><pre> clearvars</pre><pre> my1=transpose([1 1]);
my2=transpose([2 2]);
sigma=0.2;
Sigma2=sigma*eye(2);</pre><pre> %Trining points
tp=[mvnrnd(my1,Sigma2,50); mvnrnd(my2,Sigma2,50)];</pre><pre> yy=[ones(50,1);(-1)*ones(50,1)];</pre><pre> %Points to be classified
x=[mvnrnd(my1,Sigma2,100); mvnrnd(my2,Sigma2,100)];</pre><pre> %Closest points
cp=zeros(3,2);</pre><pre> %Fills the three spots
if cp(1,1)==0 && cp(1,2)==0
cp(1,1)=tp(1,1);
cp(1,2)=tp(1,2);
end
if cp(2,1)==0 && cp(2,2)==0
cp(2,1)=tp(2,1);
cp(2,2)=tp(2,2);
end
if cp(3,1)==0 && cp(3,2)==0
cp(3,1)=tp(3,1);
cp(3,2)=tp(3,2);
end</pre><pre> %Prelocating memory
CP1=zeros(1);
CP2=zeros(1);
CP3=zeros(1);</pre><pre> for ii=4:100
for k=1:3
LengthCPtoX = sqrt(((x(1,1)-cp(k,1))^2)-((x(1,2)-cp(k,2))^2));
LengthTPtoX = sqrt(((x(1,1)-tp(ii,1))^2)-((x(1,2)-tp(ii,2))^2));</pre><pre> if LengthCPtoX > LengthTPtoX
CP1=sqrt(((x(1,1)-cp(1,1))^2)-((x(1,2)-cp(1,2))^2));
CP2=sqrt(((x(1,1)-cp(2,1))^2)-((x(1,2)-cp(2,2))^2));
CP3=sqrt(((x(1,1)-cp(3,1))^2)-((x(1,2)-cp(3,2))^2));
maxCP=max([CP1 CP2 CP3]);</pre><pre> if maxCP==CP1
cp(1,1)=tp(ii,1);
cp(1,2)=tp(ii,2);
end
if maxCP==CP2
cp(2,1)=tp(ii,1);
cp(2,2)=tp(ii,2);
end
if maxCP==CP3
cp(3,1)=tp(ii,1);
cp(3,2)=tp(ii,2);
end
if cp(1,1)==tp(ii,1) || cp(2,1)==tp(ii,1) || cp(3,1)==tp(ii,1)
break
end
end
end
end</pre><pre> figure
subplot(2,1,1);
scatter(cp(:,1),cp(:,2),'b')
hold on
scatter(x(1,1),x(1,2),'r')
grid on
xlim([0 3.5]);
ylim([0 3.5]);
subplot(2,1,2);
scatter(tp(:,1),tp(:,2),'b')
hold on
scatter(x(1,1),x(1,2),'r')
grid on
xlim([0 3.5]);
ylim([0 3.5]); </pre>Joakim Hansenhttps://se.mathworks.com/matlabcentral/profile/authors/6781192-joakim-hansentag:se.mathworks.com,2005:Question/3578092017-09-21T21:35:44Z2017-09-22T02:46:40ZHow can i find number of pixel in irregular road from an image?<p>I have a binary image showing the irregular track and I have to find out the number of pixels to measure its width. Anyone have code to apply distance transform and skeleton for this problem? I have tried creating the bwdist and then skeleton and multiplying together Initially it cause error mtimes but after writing the equation as double(Dist) .* double(Skele); gives no error but results in Zero Matrix.</p>Harish Saklanihttps://se.mathworks.com/matlabcentral/profile/authors/7774324-harish-saklanitag:se.mathworks.com,2005:Question/693682013-04-01T09:30:06Z2017-09-22T02:41:12Zhow to convert gray scale image into rgb image?<p>my project is on iridiology...and it requires to convert the gray scale image to an rgb image to find the basic color of the iris.
am in need of the code to convert the gray scale image to rgb image.</p>ughttps://se.mathworks.com/matlabcentral/profile/authors/4196017-ugtag:se.mathworks.com,2005:Question/3577582017-09-21T15:24:26Z2017-09-22T02:38:51ZHow to check whether a 2d matrix is gradually increasing in values in row direction.<p>Lets say u have a matrix A=[2 4 7;3 4 6;]
So we can see the A(4)==3 in row 2 has increased from A(1)==2 progression,</p><p>And the 6th element,A(6)==6 has reduced from being A(3)==7 to 6.</p><p>So the A(6) needs to be replaced by Nan</p><p>This is basically the thing. Needs to be done in a large matrix.
Any ideas on doing it faster than for loops.</p>MSPhttps://se.mathworks.com/matlabcentral/profile/authors/8552913-msptag:se.mathworks.com,2005:Question/107952011-07-03T22:36:02Z2017-09-22T02:37:31ZCounting the number of digits<p>Hi,</p><p>how can I compute the number of digits
A=[12875]
how can I get 5 as the number of digits in A?</p>joseph Frankhttps://se.mathworks.com/matlabcentral/profile/authors/1223388-joseph-franktag:se.mathworks.com,2005:Question/3578242017-09-22T00:07:49Z2017-09-22T02:33:40ZWhy don't I have to define i?<p>This function works but why don't I have to define what i is? How does it know?</p><pre class="language-matlab">function A=circ(x)
n=length(x);
A=x;
for i=2:n
x=[x(2:n) x(1)];
A=[A;x];
end
</pre>Erin Cattersonhttps://se.mathworks.com/matlabcentral/profile/authors/10738806-erin-cattersontag:se.mathworks.com,2005:Question/3578272017-09-22T00:39:43Z2017-09-22T02:31:17ZHow to add names to table variables from a large cell with names? <p>Hello,</p><p>I have a 600x1000 array (double), where Columns have data like this...</p><pre> 145.65 18.81 29.06 28.48 ...
145.66 18.73 29.10 28.52 ...
145.64 18.77 29.02 28.49 ...
...
145.82 17.59 29.27 28.94 ...</pre><p>And have a 600 x 1 cell with Names like...</p><pre> AAA_010
AAA_002
AAA_143
...
AAA 123</pre><p>And I would like to end with a TABLE that has variable names based on the above cell with Names, like this...</p><pre> AAA_010 AAA_002 AAA_143 ... AA123
145.65 145.66 145.64 ... 145.82
18.81 18.73 18.77 ... 17.59
29.06 29.10 29.02 ... 29.27
28.48 28.52 28.49 ... 28.94
... ... ... ... ...</pre><p>Thanks for your suggestions!</p>Roberthttps://se.mathworks.com/matlabcentral/profile/authors/3899707-roberttag:se.mathworks.com,2005:Question/3577762017-09-21T17:32:51Z2017-09-22T02:29:53ZIs it possible to speed-up solving Ax=b for multiple b's by pre-computing the Cholesky factorization of A?<p>I'm currently working with large (15000x15000), sparse matrices that are not triangular nor banded, but are real, symmetric, Hermitian, and have all positive values.
Following the flow chart for the mldivide function for sparse matrices, it would appear that the Cholesky solver would be used. I solve Ax=b for multiple b's, so I thought that if I pre-computed the Cholesky factorization once, that then solving the equation would be faster, so I decided to do some tests.
These were the times I got for each step, and comparison to the usual mldivide time</p><pre class="language-matlab">>> tic; A_factor = chol(A, 'lower'); toc; %use 'lower' for speed boost with sparse matrices
Elapsed time is 51.273020 seconds.
</pre><pre class="language-matlab">>> tic; x = A_factor\b; toc; % pre-computed solution time
Elapsed time is 0.186439 seconds.
</pre><pre class="language-matlab">>> tic; x = A\b; toc; % not pre-computed solution time
Elapsed time is 3.275133 seconds.
</pre><p>It is clear that pre-computing the factorization helps (0.18s < 3.28s), but my question is why does the initial pre-computation of the Cholesky factorization take so long (~50s) when the mldivide call without the pre-computation takes only 3s and would be performing the same factorization. Wouldn't we expect the Cholesky factorization to take < 3s? Any ideas?</p>David DeVrieshttps://se.mathworks.com/matlabcentral/profile/authors/10249074-david-devriestag:se.mathworks.com,2005:Question/3577612017-09-21T15:26:56Z2017-09-22T02:28:34ZError using psnr function<p>I used [peaksnr, snr] = psnr(B, A)
wherein A is a binary image and B, the same image but a weiner2 function applied to it.</p><p>An error then is outputted</p><pre class="language-matlab">Error using psnr
</pre><pre class="language-matlab">Expected input number 1, A, to be one of these types:
</pre><pre class="language-matlab">uint8, uint16, int16, single, double
</pre><pre class="language-matlab">Instead its type was logical.
</pre><pre class="language-matlab">Error in psnr>checkImages (line 71)
validateattributes(A,validImageTypes,{'nonsparse'},mfilename,'A',1);
</pre><pre class="language-matlab">Error in psnr (line 39)
checkImages(A,ref);
</pre>Jemela Llaneshttps://se.mathworks.com/matlabcentral/profile/authors/10628809-jemela-llanestag:se.mathworks.com,2005:Question/3578132017-09-21T22:30:56Z2017-09-22T02:27:46ZHow to write a function that replaces every second sample of the audio by a zero value?<p>I have used readaudio to incorporate the wav form into a matrix: [y,Fs] = audioread.... The matrix is 165040x1 double. How would I turn every 2nd sample to zero, so every even sample. Any help would be appreciated.
Thank you.</p>Adam Kylehttps://se.mathworks.com/matlabcentral/profile/authors/11034452-adam-kyletag:se.mathworks.com,2005:Question/3578312017-09-22T01:41:44Z2017-09-22T02:26:55ZRS232 Serial communication<p>I am trying to communicate with a device via RS232. When communicating thru Windows Powershell, I wrote the following and I can receive data just fine.</p><pre> C:\> $port= new-Object System.IO.Ports.SerialPort COM67,4800,Even,7,one
C:\> $port.open()
C:\> $port.ReadLine()</pre><p>I get the expected data in Powershell just fine when I do this. The remote device is currently set RUN mode, where it output data constantly without polling.
Now, when I try to communicate with the same device thru MATLAB, I am facing issues. This is what I have written in the *.m file:</p><pre class="language-matlab">s = serial('COM67');
set(s,'BaudRate',4800, 'DataBits', 7, 'Parity', 'even', 'StopBits', 1);
fopen(s);
out = fscanf(s);
fclose(s)
delete(s)
clear s
</pre><p>I do not get an output, and get a timeout message. What am I doing wrong? Thank you.</p>Prabhat Mahatohttps://se.mathworks.com/matlabcentral/profile/authors/8744621-prabhat-mahatotag:se.mathworks.com,2005:Question/1706582015-01-20T06:40:29Z2017-09-22T02:21:11Zwhat is vertex index in BU-4DFE DATABASE<p>can any one explain what is vertex index in bu-4dfe database and for what purpose vertex index can be used in the emotion recognition in 3d/4d models.</p>KALYAN KUMARhttps://se.mathworks.com/matlabcentral/profile/authors/3637132-kalyan-kumartag:se.mathworks.com,2005:Question/1044392013-10-30T21:32:13Z2017-09-22T02:12:17ZFinding maximum of rows, colums, overall in matrix<p>I am completely stumped on a problem here. I've been playing around with it for hours now to no avail. I have to create a script that will prompt the user to enter their desired matrix
dimensions. Then perform each of the following using loops (Not using that ‘max’ built
in function’ but you may use if statements if necessary):
· Find the maximum value in each column.
· Find the maximum value in each row.
· Find the maximum value in the entire matrix.</p>Chrishttps://se.mathworks.com/matlabcentral/profile/authors/4759896-christag:se.mathworks.com,2005:Question/3578262017-09-22T00:30:46Z2017-09-22T02:00:19ZHow Can I replace specific lines in a text file<p>I'm dealing with text files and I want to replace certain lines in the text. I do not know their location but I know the text in an above and a later line to those lines.</p><p><b>Example for that text</b></p><p>TABLE: "LINK PROPERTY DEFINITIONS 02 - LINEAR"
Link="Rails Pinned" DOF=U1 Fixed=Yes
Link="Rails Pinned" DOF=U2 Fixed=Yes</p><p>TABLE: "MASS SOURCE"
MassSource=MSSSRC1 Elements=Yes Masses=Yes Loads=No IsDefault=Yes</p><p>TABLE: "MATERIAL PROPERTIES 04 - USER STRESS-STRAIN CURVES"
Material="Timber Ties" Strain=-0.00078125 Stress=-1</p><p>I would like to replace the line/lines after <b>TABLE: "MASS SOURCE"</b> and before the following word <b>TABLE:</b>
The word table repeats many times in the original text and because of that I need the following word <b>TABLE:</b>
Is it possible?</p><p>Thank you</p>Ahmed Ragehhttps://se.mathworks.com/matlabcentral/profile/authors/6833051-ahmed-ragehtag:se.mathworks.com,2005:Question/3578302017-09-22T01:40:22Z2017-09-22T01:40:22ZParticle sliding down a curvilinear path using tangential normal vectors<p>I want to create code that can solve the acceleration and velocity of a particle sliding down a curvilinear path under gravity such that I can input the path and output the acceleration and velocity as vectors. I would prefer to use tangential and normal vectors rather than work-energy relationships to highlight to students how MATLAB can numerically accomplish an otherwise difficult task.</p><p>Analytically, I know that:</p><pre> r_c = (1+(diff(path))^2)^(3/2)/(diff(diff(path)));
v_dot = -g*diff(path)/(1+(diff(path))^2)^.5;
tan_hat = [(1+diff(path)^2)^-.5; diff(path)/(1+diff(path)^2)^.5];
norm_hat = [-diff(path)/(1+diff(path)^2)^.5; (1+diff(path)^2)^-.5;</pre><p>where r_c is the radius of curvature, v_dot is the time rate change in speed, tan_hat is the tangential unit vector, and norm_hat is the normal unit vector. Path is the function that describes the path the particle is constrained to.</p><p>The acceleration is defined as</p><pre> a = v_dot.*tan_hat+v^2/r_c.*norm_hat</pre><p>where v is speed.</p><p>I am looking for code that will include all points for a given range, rather than at a specific point in time.</p><p>Thanks in advance.</p>Patrick Linfordhttps://se.mathworks.com/matlabcentral/profile/authors/11035481-patrick-linford