https://se.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-03-28T23:22:36Ztag:se.mathworks.com,2005:Question/3319302017-03-26T02:16:36Z2017-03-28T23:22:36ZCan anyone explain why Matlab gets slower and slower until restart if large cell or struct arrays are allocated and cleared repeatedly, but only on Windows, not Linux?<p>I am experiencing a serious performance problem with some matlab code that I have simplified with the attached example. I would appreciate any help in explaining how to avoid or workaround this issue, and also anyone who can run my example and confirm that they see the same result. I am very surprised at how badly this affects performance and how simple it is to reproduce (How many people are suffering from this unknowingly?). Here are some properties of this issue I've noticed:</p><ol><li>execution time increases fairly linearly with each reinitialization of a large cell array or struct array.</li><li>execution time remains slow until Matlab is restarted.</li><li>execution time of other unrelated code with different variables that also meet the criteria is affected until restart.</li><li>Only occurs if both the cell or struct array containers are large enough (around 2000 elements or more)</li><li>Only occurs if each cell element or struct array element contains a large matrix (around 200 x 200 or more)</li><li>Only occurs on Windows (Linux runs the same example code without issues). I am using Windows 7 64 bit (16GB ram)</li><li>Occurs on all recent versions of Matlab that I have tried (R2015b through R2017a)</li><li>Occurs in a script (See SlowingExecutionIssueSimple.m or the code pasted below)</li><li>Occurs in a function, but with slightly different conditions. Does not occur if the variable is persistent for certain initialization methods. Occurs if the variable is not persistent regardless of initialization method. See SlowingExecutionIssue.m for easy testing of all these cases.</li><li>After many iterations of the outer loop, the growth in execution time eventually seems to level off, but at a completely unusable level of performance compared to the first iteration.</li><li>Occurs even with fully preallocated arrays (in some cases, it occurs <i>especially</i> if fully preallocated - see struct array example in SlowingExecutionIssue.m for case where incomplete preallocation avoids this problem)</li><li>"clear all" and "clear classes" have no effect.</li></ol><p>Thanks in advance for any help with this. So far I have only been able to work around it in my application code by making variables persistent inside a function and avoiding reinitialization (i.e. reinitializing only one element at a time inside the innermost loop). It is not always possible to work around it and requires constant use of the memory that could otherwise be freed. Is this a bug in how Matlab manages memory?, or an unavoidable side effect of windows memory management? If it doesn't get fixed soon, I may have to switch permanently to Linux to avoid this issue.</p><pre class="language-matlab">iter = 10000;
for i = 1:10
tic;
a0 = ones(221,241);
a = a0;
% c=cell(iter,1);%Cell array example. The problem only occurs if c is reinitialized each time
f = repmat(struct('a',a),1,iter);%Struct array example. Struct array with all elements populated with "a"
for j=1:iter
%a has to change each iteration or the issue doesn't show up
a=a+1;%Change the variable
a=a-1;%Change the variable back to original value
% c{j}=a;%This causes serious slowdown with each run
f(j).a = a;%This causes serious slowdown with each run
% c{j}=a0;%This runs fast even though a0 is identical in size, type, and value to a
% f(j).a = a0;%This runs fast
end
toc
end
</pre><p>Here is the output I get from this script:</p><pre class="language-matlab">>> SlowingExecutionIssueSimple
Elapsed time is 1.227035 seconds.
Elapsed time is 1.336831 seconds.
Elapsed time is 1.349026 seconds.
Elapsed time is 1.426942 seconds.
Elapsed time is 1.568531 seconds.
Elapsed time is 1.779247 seconds.
Elapsed time is 2.051785 seconds.
Elapsed time is 2.412232 seconds.
Elapsed time is 2.857880 seconds.
Elapsed time is 3.500180 seconds.
>> clear all
>> clear classes
>> SlowingExecutionIssueSimple
Elapsed time is 2.254901 seconds.
Elapsed time is 4.609098 seconds.
Elapsed time is 5.811552 seconds.
Elapsed time is 6.322061 seconds.
Elapsed time is 6.974427 seconds.
Elapsed time is 7.242437 seconds.
Elapsed time is 7.527272 seconds.
Elapsed time is 7.704636 seconds.
Elapsed time is 8.079658 seconds.
Elapsed time is 8.315676 seconds.
>>
</pre>Reedhttps://se.mathworks.com/matlabcentral/profile/authors/6808-reedtag:se.mathworks.com,2005:Question/3324092017-03-28T20:56:54Z2017-03-28T23:21:36ZQuestion surf() fuction<p>I am generationg a revolution solid of a gaussian fuction and when I use the surf() fuction I get the graphic that I need, but I have to get this figure in a matrix NxN with each element of this matrix be a gray value (it will be my height) but I don´t know how do it!</p><p>Can you help me?</p><p>This is my code:</p><pre> r = x(1:1024); %0:0.1:30; x(513:1024)
z = gaussmf(r,[13.32 0]);%exp(-r.^2/(2*(13.32).^2));
theta = 0:pi/20:2*pi;
xx = bsxfun(@times,r',cos(theta));
yy = bsxfun(@times,r',sin(theta));
zz = repmat(z',1,length(theta));</pre><p>figure()
surf(xx,yy,zz)
axis equal</p>Esteban Suárezhttps://se.mathworks.com/matlabcentral/profile/authors/9851883-esteban-suareztag:se.mathworks.com,2005:Question/3324222017-03-28T22:42:30Z2017-03-28T23:20:56ZI'm attempting to write a function that calculates the value of sine using a taylor series to within a tolerance of 10^-6. I think my loop is set up correctly but i'm not sure the series equation is correct as my function never stops running. <pre class="language-matlab">function [y] = homework11(x)
y1=0;
y=0;
tolerance=0.000001;
a=sin(x);
n=1;
while y<(a-tolerance)
y1(n)=y1+((-1).^(n))*(x.^(2*(n+1))/factorial(2*(n+1)));
n=n+1;
y=sum(y1);
end
</pre>Nathan Pratt-Holthttps://se.mathworks.com/matlabcentral/profile/authors/9506879-nathan-pratt-holttag:se.mathworks.com,2005:Question/3323362017-03-28T14:11:15Z2017-03-28T23:16:52ZHeart Rate by category<p>Hi,</p><p>I want to organize heart rate by the time spent in 3 diferent categories:
0 - 50 bpm
50 - 100 bpm
100 - 200 bpm</p><p>what is the best code??</p><p>thank you</p>Sérgio Queridohttps://se.mathworks.com/matlabcentral/profile/authors/6420976-sergio-queridotag:se.mathworks.com,2005:Question/3324142017-03-28T21:25:53Z2017-03-28T23:16:39ZWhat is the quickest way to find a gradient or finite difference in Matlab of a real function in high dimensions?<p>I have a function handle (black box) that gives me the value of f which is a real number and a function of multiple variables. What is the most efficient way to calculate the gradient or finite differences for f?</p><p>Currently I am doing it as follow but I would like to avoid looping in Matlab if that helps speed up my code:</p><pre class="language-matlab">function [ dU_dW ] = numerical_gradient(W,f,eps)
%compute GD update numerically
[D1, D2] = size(W);
dU_dW = zeros(D1, D2);
for d1=1:D1
for d2=1:D2
e = zeros([D1,D2]);
e(d1,d2) = eps;
f_e1 = f(W+e);
f_e2 = f(W-e);
%numerical_derivative = (f_e1 - f_e2)/(2*eps);
numerical_derivative = f_e1 - f_e2;
dU_dW(d1,d2) = numerical_derivative;
end
end
end
</pre><p>----</p><p>I did see the following:</p><p>https://www.mathworks.com/help/matlab/ref/gradient.html</p><p>but it doesn't seem to take function handles as input.</p>Brando Mirandahttps://se.mathworks.com/matlabcentral/profile/authors/2706824-brando-mirandatag:se.mathworks.com,2005:Question/3323262017-03-28T13:12:31Z2017-03-28T23:11:26ZHow do I use nlinfit to solve for constants in multiple ordinary differential equations (multiple sets of time dependent data)?<p>Basically, my assignment is to use sets of initial time vs. concentration data for six compounds/entities in nlinfit in order to find the k1, k2, k3, k4, k5 and k6 constants in the six differential equations simultaneously. The differential equations are shown in the code day. k0 was based off of literature values.</p><p>I'm not sure exactly what i am doing wrong. The error i'm getting now is that the dependent variable (c) can't be a matrix, but has to be a vector. However, I have six different variables dependent on time. So, maybe I need to use nlinfit six times, once for each variable? All help is appreciated greatly!</p><p>Here is my code so far code:</p><p>Main file:</p><p>tspan=[0,5,10,15,20,25,30,35,40,45,50]';</p><p>TG=[1,0.361,0.238,0.15,0.145,0.14,0.122,0.117,0.114,0.112,0.111]';</p><p>DG=[0,0.183,0.13,0.101,0.086,0.079,0.075,0.072,0.071,0.070,0.069]';</p><p>MG=[0,0.063,0.035,0.025,0.021,0.019,0.018,0.018,0.017,0.017,0.017]';</p><p>Al=[6,4.655,3.651,3.966,3.630,3.630,3.535,3.515,3.502,3.495,3.491]';</p><p>E=[0,1.745,2.148,2.200,2.369,2.429,2.464,2.484,2.497,2.504,2.508]';</p><p>GL=[0,0.411,0.615,0.702,0.746,0.770,0.784,0.792,0.797,0.799,0.801]';</p><p>c=[TG DG MG Al E GL];</p><p>k0=[0.04, 0.20, 0.225, 1.4, 0.22, 0.088];</p><p>[k, resid, J] = nlinfit(tspan, c, @HW2regress,k0)</p><p>function y = HW2regress(k, tspan)</p><p>k1=k(1); k2=k(2); k3=k(3); k4=k(4); k5=k(5); k6=k(6);</p><p>TG=c(:,1);</p><p>DG=c(:,2);</p><p>MG=c(:,3);</p><p>A=c(:,4);</p><p>E=c(:,5);</p><p>GL=c(:,6);</p><pre> function [dS] = HW2ode(t,c)</pre><pre> %system of ODEs</pre><pre> %TG</pre><pre> dS(1,1)=-k1.*TG.*A+k2.*DG.*E;</pre><pre> %DG</pre><pre> dS(2,1)=k1.*TG.*A-k2.*DG.*E-k3.*DG.*A+k4.*MG.*E;</pre><pre> %MG</pre><pre> dS(3,1)=k3.*DG.*A-k4.*MG.*E-k5.*MG.*A+k6.*GL.*E;</pre><pre> %E</pre><pre> dS(4,1)=k1.*TG.*A-k2.*DG.*E+k3.*DG.*A-k4.*MG.*E+k5.*MG.* k6.*GL.*E;</pre><pre> %A</pre><pre> dS(5,1)=-dS(4,1);</pre><pre> %GL</pre><pre> dS(6,1)=k5.*MG.*A-k6.*GL.*E;</pre><pre> end</pre><p>c0=[1,0,0,0,6,0];</p><p>tspan=[0,5,10,15,20,25,30,35,40,45,50]';</p><p>[t,y]=ode45(@HW2ode,tspan,c0);</p><p>end</p>Daniel Konovalovhttps://se.mathworks.com/matlabcentral/profile/authors/7657358-daniel-konovalovtag:se.mathworks.com,2005:Question/3323642017-03-28T16:55:06Z2017-03-28T23:07:07ZPutting plot title one only one line<p>I am trying to run the following code:</p><pre class="language-matlab">t = datetime(2006, 01, 01):calmonths(1):datetime(2100, 12, 01);
x = 1:100;
y = 1:100;
</pre><pre class="language-matlab">for i = 1:12
subplot(6,2,i)
plot(x*i,y)
title(['It is ' month(t(i), 'name')])
end
</pre><p>But the title is forced onto a second line, does anyone know how to keep it on only one line?</p>Collin Tuttlehttps://se.mathworks.com/matlabcentral/profile/authors/8571184-collin-tuttletag:se.mathworks.com,2005:Question/3324132017-03-28T21:20:06Z2017-03-28T23:05:38ZWarning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN ODE15s<p>Hi everyone!
I'm writing a code to simulate a car's 2D rigid motion: I need to contemporarily solve 35 equations, 7 differential and 28 algebraic, so I'm using ODE15s.
Simpler version of this model (up to 19 equations) worked (after long fights), but now I'm stuck: after declaring where differential equations are in the M matrix, Matlab warns me that:</p><pre class="language-matlab">"Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN"
</pre><pre> What shall I do to sort this out?</pre><p>Here's the code (pacejka and slittamenti are functions):</p><pre class="language-matlab">M(13,13)=1;
M(14,14)=1;
M(15,15)=1;
M(24,24)=1;
M(25,25)=1;
M(26,26)=1;
M(27,27)=1;
</pre><pre class="language-matlab">options = odeset('Mass',M,'RelTol',1e-8,'AbsTol',tolleranze);
</pre><pre class="language-matlab">y0_=[alfa_1_0;
alfa_1_0;
alfa_2_0;
alfa_2_0;
F_y_1_0;
F_y_1_0;
F_y_2_0;
F_y_2_0;
F_x_1_0;
F_x_1_0;
F_x_2_0;
F_x_2_0;
v0;
r0;
u_0;
Z_statico_1;
Z_statico_1;
Z_statico_2;
Z_statico_2;
slip_ratio_1_0;
slip_ratio_1_0;
slip_ratio_2_0;
slip_ratio_2_0;
omega_1_0;
omega_1_0;
omega_2_0;
omega_2_0;
schiacciamento_1_0;
schiacciamento_1_0;
schiacciamento_2_0;
schiacciamento_2_0;
R_puro_rotolamento_1_0;
R_puro_rotolamento_1_0;
R_puro_rotolamento_2_0;
R_puro_rotolamento_2_0];
</pre><pre class="language-matlab">[t,y] = ode15s(@(t,y) longitudinale_puro_nomi_veri(t,y,J_1,J_2,...
delta_v_0,tau_1,tau_2,a_1,a_2,t_1,t_2,m,J_z,J_zx,...
dati_pacejka_r,dati_pacejka_f,R_1,R_2,g,h,Cz_1,Cz_2,...
Z_statico_1,Z_statico_2,...
theta_11,theta_12,theta_21,theta_22,l,tspan),tspan,y0,options);
</pre><p>Here's the function where all the equations are written:</p><pre class="language-matlab">function out=longitudinale_puro_nomi_veri(t,y,J_1,J_2,...
delta_v_0,tau_1,tau_2,a_1,a_2,t_1,t_2,m,J_z,J_zx,...
dati_pacejka_r,dati_pacejka_f,R_1,R_2,g,h,Cz_1,Cz_2,...
Z_statico_1,Z_statico_2,...
theta_11,theta_12,theta_21,theta_22,l,tspan)
</pre><pre class="language-matlab">delta_v=0;
</pre><pre class="language-matlab">momento_11=0; % Torque
momento_12=0;
momento_21=0;
momento_22=0;
</pre><pre class="language-matlab">delta_11=tau_1*delta_v; % Wheel angles
delta_12=tau_1*delta_v;
delta_21=tau_2*delta_v;
delta_22=tau_2*delta_v;
</pre><pre class="language-matlab">% Unknowns:
alfa_11=y(1);
alfa_12=y(2);
alfa_21=y(3);
alfa_22=y(4);
F_y_11=y(5);
F_y_12=y(6);
F_y_21=y(7);
F_y_22=y(8);
F_x_11=y(9);
F_x_12=y(10);
F_x_21=y(11);
F_x_22=y(12);
v=y(13);
r=y(14);
u=y(15);
F_z_11=y(16);
F_z_12=y(17);
F_z_21=y(18);
F_z_22=y(19);
epsilon_11=y(20);
epsilon_12=y(21);
epsilon_21=y(22);
epsilon_22=y(23);
omega_11=y(24);
omega_12=y(25);
omega_21=y(26);
omega_22=y(27);
schiacciamento_11=y(28);
schiacciamento_12=y(29);
schiacciamento_21=y(30);
schiacciamento_22=y(31);
R_pr_11=y(32);
R_pr_12=y(33);
R_pr_21=y(34);
R_pr_22=y(35);
</pre><pre class="language-matlab">out=[-alfa_11+delta_11-atan((v+r*a_1)/(u-r*t_1/2)); % Congruenza: deriva alfa_11
-alfa_12+delta_12-atan((v+r*a_1)/(u+r*t_1/2)); % Congruenza: deriva alfa_12
-alfa_21+delta_21-atan((v-r*a_2)/(u-r*t_2/2)); % Congruenza: deriva alfa_21
-alfa_22+delta_22-atan((v-r*a_2)/(u+r*t_2/2)); % Congruenza: deriva alfa_22
-F_y_11+pacejka('Fy0',F_z_11,0,-alfa_11*180/pi,-epsilon_11,dati_pacejka_f); % Legame costitutivo F_y_11
-F_y_12+pacejka('Fy0',F_z_12,0,-alfa_12*180/pi,-epsilon_12,dati_pacejka_f); % Legame costitutivo F_y_12
-F_y_21+pacejka('Fy0',F_z_21,0,-alfa_21*180/pi,-epsilon_21,dati_pacejka_r); % Legame costitutivo F_y_21
-F_y_22+pacejka('Fy0',F_z_22,0,-alfa_22*180/pi,-epsilon_22,dati_pacejka_r); % Legame costitutivo F_y_22
-F_x_11+pacejka('Fx0',F_z_11,0,-alfa_11*180/pi,-epsilon_11,dati_pacejka_f); % Legame costitutivo F_x_11
-F_x_12+pacejka('Fx0',F_z_12,0,-alfa_12*180/pi,-epsilon_12,dati_pacejka_f); % Legame costitutivo F_x_12
-F_x_21+pacejka('Fx0',F_z_21,0,-alfa_21*180/pi,-epsilon_21,dati_pacejka_r); % Legame costitutivo F_x_21
-F_x_22+pacejka('Fx0',F_z_22,0,-alfa_22*180/pi,-epsilon_22,dati_pacejka_r); % Legame costitutivo F_x_22
(F_y_11+F_y_12+F_y_21+F_y_22)/m-u*r; % Equilibrio trasversale
((F_y_11+F_y_12)*a_1-(F_y_21+F_y_22)*a_2)/J_z; % Equilibrio imbardata
(F_x_11+F_x_12+F_x_21+F_x_22)/m-(F_y_11*delta_11+F_y_12*delta_12)/m+v*r; % Equilibrio longitudinale
-F_z_11+Z_statico_1-theta_11*(F_y_11+F_y_12+F_y_21+F_y_22)-theta_12*((F_y_11+F_y_12)*a_1-(F_y_21+F_y_22)*a_2)-(F_x_11+F_x_12+F_x_21+F_x_22-(F_y_11*delta_11+F_y_12*delta_12))*h/l;
-F_z_12+Z_statico_1+theta_11*(F_y_11+F_y_12+F_y_21+F_y_22)+theta_12*((F_y_11+F_y_12)*a_1-(F_y_21+F_y_22)*a_2)-(F_x_11+F_x_12+F_x_21+F_x_22-(F_y_11*delta_11+F_y_12*delta_12))*h/l;
-F_z_21+Z_statico_2-theta_21*(F_y_11+F_y_12+F_y_21+F_y_22)-theta_22*((F_y_11+F_y_12)*a_1-(F_y_21+F_y_22)*a_2)+(F_x_11+F_x_12+F_x_21+F_x_22-(F_y_11*delta_11+F_y_12*delta_12))*h/l;
-F_z_22+Z_statico_2+theta_21*(F_y_11+F_y_12+F_y_21+F_y_22)+theta_22*((F_y_11+F_y_12)*a_1-(F_y_21+F_y_22)*a_2)+(F_x_11+F_x_12+F_x_21+F_x_22-(F_y_11*delta_11+F_y_12*delta_12))*h/l;
-epsilon_11+scorrimento_11(u,R_pr_11,omega_11); % Congruenza: slip x_11
-epsilon_12+scorrimento_12(u,R_pr_12,omega_12); % Congruenza: slip x_12
-epsilon_21+scorrimento_21(u,R_pr_21,omega_21); % Congruenza: slip x_21
-epsilon_22+scorrimento_22(u,R_pr_22,omega_22); % Congruenza: slip x_22
(momento_11-F_x_11*(R_1-schiacciamento_11))/J_1; % Bilancio ruota 11
(momento_12-F_x_12*(R_1-schiacciamento_12))/J_1; % Bilancio ruota 12
(momento_21-F_x_21*(R_2-schiacciamento_21))/J_2; % Bilancio ruota 21
(momento_22-F_x_22*(R_2-schiacciamento_22))/J_2; % Bilancio ruota 22
-schiacciamento_11+F_z_11/Cz_1; % Schiacciamento 11
-schiacciamento_12+F_z_12/Cz_1; % Schiacciamento 12
-schiacciamento_21+F_z_21/Cz_2; % Schiacciamento 21
-schiacciamento_22+F_z_22/Cz_2; % Schiacciamento 22
-R_pr_11+R_1-schiacciamento_11/3; % Raggio puro rotolamento 11
-R_pr_12+R_1-schiacciamento_12/3; % Raggio puro rotolamento 12
-R_pr_21+R_2-schiacciamento_21/3; % Raggio puro rotolamento 21
-R_pr_22+R_2-schiacciamento_22/3]; % Raggio puro rotolamento 22
</pre>Francesco Ardiahttps://se.mathworks.com/matlabcentral/profile/authors/9389093-francesco-ardiatag:se.mathworks.com,2005:Question/1188852014-02-24T18:27:53Z2017-03-28T23:03:42Zlsline shifts the yaxis upwards <p>I am plotting four points:</p><p>x = [-0.13; -0.31; -1.07; -0.85]
y = [-2.58; 5.21; -0.80 ; -1.14]</p><p>plot (x,y,'o')</p><p>x-axis and y-axis minimum and maximum should be same (both axes should have same scale)
Here, -3 is minimum limit and 6 is maximum limit for both x and y axes.</p><p>I use lsline function to plot the least square fit line. Though both axes have same scale, however the y axis shifts upwards. ( -3 the minimum point on y axis shifted upwards)</p><p>Y-axes has less distance between the tick points. Please see the figure.</p><p>I don't know why? Please help.</p><img src = "/matlabcentral/answers/uploaded_files/8618/untitled.jpg">Priyahttps://se.mathworks.com/matlabcentral/profile/authors/4211146-priyatag:se.mathworks.com,2005:Question/3324242017-03-28T23:02:40Z2017-03-28T23:02:40ZHow to add wave to logic analyzer<p>I have followed the way in help menu to log some signals in simulink. However, it didn't appear in the logic analyzer. In some former version of Matlab, it sometimes reports error and terminates the Matlab.</p>Jieming Xuhttps://se.mathworks.com/matlabcentral/profile/authors/5629494-jieming-xutag:se.mathworks.com,2005:Question/3324232017-03-28T22:50:46Z2017-03-28T22:50:46ZHow to make an analog clock in GUI Matlab?<p>What is the code for making an analog clock that represents the time on your own computer? in GUI matlab program.</p>Alysa Vendittihttps://se.mathworks.com/matlabcentral/profile/authors/9698271-alysa-vendittitag:se.mathworks.com,2005:Question/736392013-04-26T05:12:10Z2017-03-28T22:46:47Zsending and receiving IMAGE using serial port(USB to serial)<p>Hi friends,</p><p>Actually I have an image which need to be transferred via serial port. As my laptop dosent contain serial port i am using USB to serial convertor.I am sending image from one computer other using two USB to serials and null modem. I am doing this for testing purpose and later null modem will be replaced by 8051 controller. I wrote a code for transferring but i am unable to receive data proper control. Please check the below code.</p><p><b>For Transfering</b></p><pre class="language-matlab">if true
</pre><pre> SendData=serial('COM1','BaudRate',256000);
fopen(SendData);
[rows,columns]=size(Encryptedimage);
for k=1:3
for i=1:rows
for j=1:columns
data=num2str(EncryptedImage(i,j,k));
fprintf(SendData, '%c' , '*');
fprintf(SendData, '%s',data);
end
end
end
fclose(SendData);
delete(SendData);
clear SendData;</pre><pre class="language-matlab">end
</pre><p><b>For receiving</b></p><pre class="language-matlab">if true
</pre><pre class="language-matlab">recData=serial('COM2','BaudRate',256000);
fopen(recData);
while(1)
Input1=fread(receiveTemp)
</pre><pre> if(isempty(Input1))
continue;
else
disp('Value received')
for k=1:3
for i=1:rows
for j=1:columns</pre><pre> Input1=char(Input1);
Input1=sscanf(Input1, '%d');
EncryptedImage1(i,j,k)=Input1;
Input1=fread(receiveTemp);</pre><pre> end
end
end
end
if(i==rows & j==columns & k==3)
break;
end
end</pre><pre class="language-matlab">end
</pre><p>Now problem is while receiving Input1 is getting around 120 values at a time.
please help me in rectifying this issue.</p>srikanthhttps://se.mathworks.com/matlabcentral/profile/authors/3816884-srikanthtag:se.mathworks.com,2005:Question/3320682017-03-27T05:24:10Z2017-03-28T22:36:12Zfigure not coming up<p>I have written a code in which i have created a rectangular surface using patch command and i m rotating this surface about z axis using the angles i get from my mobile's gyro using udp object.But as irun the code no errors show up but also there is no figure coming up.My code is</p><pre> instrreset</pre><pre class="language-matlab">a=[1 ,-1 ,-1, 1, 1];
b=[1 ,1 ,-1, -1,1];
z=zeros(1,5);
x=zeros(1,5);
y=zeros(1,5);
</pre><p>%Creating UDP object
UDPComIn=udp('192.168.173.154','LocalPort',12345);
set(UDPComIn,'DatagramTerminateMode','off')</p><pre class="language-matlab">while 1
</pre><pre> fopen(UDPComIn);
csvdata=fscanf(UDPComIn);
scandata=textscan(csvdata,'%s %f %f %f %f %f','Delimiter',',');
data=[scandata{4},scandata{5},scandata{6}];</pre><pre class="language-matlab">fclose(UDPComIn);
alph=data(1);
</pre><pre> for i=1:1:4
t1=[cosd(alph) ,(-sind(alph));sind(alph) ,cosd(alph)];
k=[a(i); b(i)];
m=t1*k;
x(i)=m(1);
y(i)=m(2);
x(5)=x(1);
y(5)=y(1);
end</pre><pre> view(3);</pre><p>patch(x',y',z');</p><pre> xlabel('XXX');
ylabel('YYY');
zlabel('ZZZ');</pre><pre class="language-matlab">k=k+1;
%CodeEnd
end
</pre><p>but when i run the same patch command while not receiving data from udp just giving angles through for loop it shows no error and figure is also visible.Can anyone plz help me with this problem?</p>taher azimhttps://se.mathworks.com/matlabcentral/profile/authors/6755192-taher-azimtag:se.mathworks.com,2005:Question/3320262017-03-26T19:39:47Z2017-03-28T22:26:59Zhi ı am a master student and I have a home work<p>I have A BİNARY PİCTURE AND I WANT TO CALCULATE İT'S MAXİMUM width and length.can you help me?</p>hasan güneshttps://se.mathworks.com/matlabcentral/profile/authors/9989524-hasan-gunestag:se.mathworks.com,2005:Question/3324212017-03-28T22:21:01Z2017-03-28T22:23:53ZJSON decode data format<p>I am attempting to use the <a href = "https://www.mathworks.com/help/matlab/ref/jsondecode.html">jsondecode function</a> to look at weather data via an API. The issue I am running into is that the format of data type in Matlab changes depending on what is returned.</p><p>For example, if I am look at 5 days, and all 5 days have the same information (such as Temperature, wind speed, humidity, and chance of precipitation), then Matlab will format the data as a structure array. So then I access individual values using smooth parentheses ( ).</p><p>However, if one of the days is different, then Matlab will format the data as a cell array of scalar structures. Say that it happened to rain one day, then it might add the field "precipitation type". Now since one day is different, I must access the data using curly braces { }.</p><p>Is there any way to avoid this? Or force it to use certain formatting all the time? (Such as always returning it as always using a cell array format?)</p>peaksixhttps://se.mathworks.com/matlabcentral/profile/authors/9936637-peaksixtag:se.mathworks.com,2005:Question/3324192017-03-28T21:58:55Z2017-03-28T22:19:23ZDistance between two functions<p>I'm creating multiple probability density functions (pdfs), comprised of x and y values, and would like to compare these to another given pdf (each one has the same number of points). Would something as simple as a dot product be sufficient? Or should I use a Euclidean distance, where I find the distance between each of the points and take the square root of the sum of their squares? This is mainly to compare them to see how similar they are. I need a standard metric to compare them all evenly against the same pdf to find which ones are similar and which aren't.</p><p>Thanks!</p>Tyler Critchfieldhttps://se.mathworks.com/matlabcentral/profile/authors/7826474-tyler-critchfieldtag:se.mathworks.com,2005:Question/3323752017-03-28T17:41:22Z2017-03-28T22:17:58ZHow can I connect two plotted points in a timeseries with a vertical line?<p>I wrote a script that extracts data from a weather station so that I have a timeseries for the average temperature, high temp, and low temp for each day in a year. On the timeseries plot I would like to connect the high and low temp for each day with a vertical line. Is there a way to do this?</p>Katie Sherrickhttps://se.mathworks.com/matlabcentral/profile/authors/10037919-katie-sherricktag:se.mathworks.com,2005:Question/3322222017-03-27T23:15:36Z2017-03-28T22:17:37ZHow difficult is it to convert our analysis (30 functions, 7000 lines) into a standalone executable?<p>We recently made a data analysis pipeline in Matlab that produces tables and figures for some biology data. We'd like to share our methods with as many users as possible. Since that includes people without a Matlab license, we're considering converting our entire package into a standalone executable using deploytool.</p><p>Given that we'd like to do this for the whole pipeline (30 functions, 7000 lines), not just a single function, <b>how difficult is this going to be</b>?</p><p>From <a href = "https://www.mathworks.com/matlabcentral/answers/4864-how-to-run-standalone-exe-file-on-computer-without-matlb">Walter Roberson's answer to a similar question</a> it sounds like this could be tricky.</p>Greghttps://se.mathworks.com/matlabcentral/profile/authors/3110703-gregtag:se.mathworks.com,2005:Question/3324162017-03-28T21:41:22Z2017-03-28T22:14:45ZSplitting image in matlab<p>Need to split an image in matlab into 4 quadrants and swap the top left and bottom left quadrants</p>Lucas Buckelshttps://se.mathworks.com/matlabcentral/profile/authors/10039171-lucas-buckelstag:se.mathworks.com,2005:Question/3324182017-03-28T21:53:58Z2017-03-28T22:07:38ZWe want to port code generated by deploytool to many different OS. Do we need to run deploytool on every OS?<p>We have MATLAB software we'd like to share with non-MATLAB users. Packaging it into a standalone executable with deploytool sounds like a good way to do this. However, since</p><p>1. we don't know the OS of the users, and</p><p>2. deploytool only makes executables that can be run in the same OS they were made in</p><p><b>do we need to run deploytool in every potential OS</b>?</p><p>If so, this sounds prohibitive. Is there anything that would make it easier? e.g. Is it backward compatible, meaning we could run deploytool once in the newest Mac/Windows/Linux OS and the executable would run in all older versions of the OS?</p>Greghttps://se.mathworks.com/matlabcentral/profile/authors/3110703-gregtag:se.mathworks.com,2005:Question/3323852017-03-28T18:34:17Z2017-03-28T22:01:51ZPleas Help me!<p>I am a apprentice to use Matlab.
I do not know much more.
And i want to code for a program in the stability analysis of system with time-varying delay,
it is similar to the methods that the numerical list in the table attached below.</p>Le Minh Tonhttps://se.mathworks.com/matlabcentral/profile/authors/10021662-le-minh-tontag:se.mathworks.com,2005:Question/3323312017-03-28T13:34:29Z2017-03-28T21:59:50ZCreating a loop of a script<p>Hi,</p><p>I need to loop a script but i dont know how with using the for function</p><p>If i copy the script down it will continue on and work but this isn't very productive</p><p>The script is:</p><pre class="language-matlab">t_step=0.1
s_step=0.5 % Distance step of 0.5m
s_Zero=0
s=s_Zero+s_step
t=0
v_Zero=v_Lat
a=0.1; % Long Acceleration
% Loop starts Here
v=v_Zero+(a*t_step);
Tractive_Force_Tyre=mu_Long*((2.006*v*v*wdR)+(g*m*wdR)+(m*a*H/L)); % Zero Acceleration
if v<Max_First
Tf=Tf_First;
elseif (Max_First<v) && (v<Max_Second)
Tf=Tf_Second;
elseif (Max_Second<v) && (v<Max_Third)
Tf=Tf_Third;
elseif (Max_Third<v) && (v<Max_Fourth)
Tf=Tf_Fourth;
elseif (Max_Fourth<v) && (v<Max_Fifth)
Tf=Tf_Fifth;
else (Max_Fifth<v) && (v<Max_Sixth)
Tf=Tf_Sixth;
end
if Tractive_Force_Tyre>Tf;
disp('Engine Limited');
a_end=Tf/m;
else Tf>Tractive_Force_Tyre;
disp('Traction Limited');
a_end=Tractive_Force_Tyre/m;
end
v_Zero=v;
s_Zero=s;
a=a_end;
t_step=((sqrt((2*a.*s)+(v_Zero^2))-v_Zero)/a);
v=v_Zero+(a*t_step);
t=t+t_step;
s=s_step+s;
% Loop Finish Here
</pre>Conor Hardimanhttps://se.mathworks.com/matlabcentral/profile/authors/5045480-conor-hardimantag:se.mathworks.com,2005:Question/3324202017-03-28T21:59:49Z2017-03-28T21:59:49ZHow to filter Acceleromter RAW values - pedometer?<p>Hy,I m using IMU sensor, from that I want to some data analysis make with RAW accelerometer - step counter.</p><p>I want to use some of the this method: <a href = "https://www.mathworks.com/help/supportpkg/mobilesensor/examples/counting-steps-by-capturing-acceleration-data-from-your-android-device.html">Counting Steps - MathWorks</a> <a href = "https://www.mathworks.com/matlabcentral/fileexchange/42821-android-sensor-data-acquisition-accelerometer-example/content/Accelerometer/StepCounter.m">MathWorks - zero crossing</a></p><p>but my vector of the x,y,z is too noise, how can I get smooth data?
I tried to smooth the signal, but I must use 8-10 times the smooth function.</p><pre> I need some elegant way to do that. Can you give some ideas ?</pre>x yhttps://se.mathworks.com/matlabcentral/profile/authors/3403395-x-ytag:se.mathworks.com,2005:Question/3318962017-03-25T17:31:24Z2017-03-28T21:53:20ZThe Pitch of signal <p>Hello sir,
According to my knowledge pitch of any signal is nothing but its frequency, so if i keep the same frequency of any signal then the audio that we hear should be same right? While I was working with matlab, what I did is, I kept the frequency same but changed the sampling rate(for the same sinusoid), the result is I got the different sound for 2 different sampling rates. How can that be possible? can you please explain it to me?</p><p>Thank you</p>Nachiket Patkihttps://se.mathworks.com/matlabcentral/profile/authors/6912172-nachiket-patkitag:se.mathworks.com,2005:Question/3323972017-03-28T19:36:39Z2017-03-28T21:46:22Z'Not enough input arguments' error when using integral function<p>So i have this function</p><pre> function y = aRIC_rea(W,x)</pre><pre> R=W(1); Rp=W(2); Cp=W(3); I=W(4); Ce=W(5);</pre><pre> A=1+((2*pi*x).*Rp*Cp).*((2*pi*x).*Rp*Cp);</pre><pre> a1= (2*pi*x).*(I.*A-Rp*Rp*Cp);
a2= A.*(1-(2*pi*x).*(2*pi*x)*I*Ce)+(2*pi*x).*(2*pi*x)*Rp*Rp*Cp*Ce;
a3= R.*A+Rp;
num= a1.*a2-(2*pi*x).*a3.*a3*Ce;</pre><pre> a4= (2*pi*x).*Ce.*a3;
denom= a2.*a2+a4.*a4;</pre><pre> y= num./denom;</pre><pre> end</pre><p>I try to integrate in a separate script</p><pre> W1 = [0.8329 5.9045 0.0178 0.0032 0.0011]
X1 = reshape(X,1,24)
funRea = @(W1,X1)aRIC_rea(W1,X1)
q = integral(funRea,5,Xres)</pre><p>I get this error</p><pre> funRea = </pre><pre> @(W1,X1)aRIC_rea(W1,X1)</pre><pre> Not enough input arguments.</pre><pre> Error in static0analysisaric>@(W1,X1)aRIC_rea(W1,X1)</pre><pre> Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);</pre><pre> Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);</pre><pre> Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);</pre><pre> Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);</pre><pre> Error in static0analysisaric (line 55)
q = integral(funRea,5,Xres)</pre>Gabriel Jenkinshttps://se.mathworks.com/matlabcentral/profile/authors/7065505-gabriel-jenkinstag:se.mathworks.com,2005:Question/3322732017-03-28T08:38:29Z2017-03-28T21:45:26ZIs it possible to use my matlab code as input for arduino , if yes please help me and tell the procedure to interface arduino with matlab.? thanks in advance.<p>I have a matrix variable 't' in my matlab code which contains some values say 1,2,3,4 etc. Now I want to interface this code to arduino such that if the matrix 't' contains value '1' then one of the pin in arduino say pin11 should get a output for me which I would like to use for switching.If 't' contains value '2' then another pin in arduino should act as output. Is it possible for me to get this output?</p>krishna kireetihttps://se.mathworks.com/matlabcentral/profile/authors/9473003-krishna-kireetitag:se.mathworks.com,2005:Question/3324172017-03-28T21:42:46Z2017-03-28T21:42:46ZWhere is LiBatteryElements library that will work with R2017a?<ul><li>I am trying to run the R2012b sc_lithium_cell_1RC.mdl under R2017a. When I try and run I get the following errors.</li><li></li><li>Multiple compilation errors detected while compiling ssc_lithium_cell_1RC.</li><li>Caused by:</li><li>['ssc_lithium_cell_1RC/Lithium Cell (1RC equivalent circuit model)/C1']: Cannot find parameter 'i'. Please run ssc_build if you have made changes to Simscape file or if you are upgrading to a new version of Simscape.</li><li>['ssc_lithium_cell_1RC/Lithium Cell (1RC equivalent circuit model)/Em_table']: Cannot find parameter 'Qe'. Please run ssc_build if you have made changes to Simscape file or if you are upgrading to a new version of Simscape.</li><li>['ssc_lithium_cell_1RC/Lithium Cell (1RC equivalent circuit model)/R0']: Cannot find parameter 'i'. Please run ssc_build if you have made changes to Simscape file or if you are upgrading to a new version of Simscape.</li><li>['ssc_lithium_cell_1RC/Lithium Cell (1RC equivalent circuit model)/R1']: Cannot find parameter 'i'. Please run ssc_build if you have made changes to Simscape file or if you are upgrading to a new version of Simscape.</li><li></li><li>Subsequently I try to run the ssc_build on LiBatteryElements, BUT... that library doesn't exist in 2012b. However it is in 2010b. I copied it into my working directory and rerun sec_build. Now I see this:</li><li></li><li>Failed to generate 'LiBatteryElements_lib'</li><li></li><li>Caused by:</li><li>Error using LiBatteryElements.C_table>equations (line 43)</li><li>Function, tablelookup, is wrong. Please check 1) whether input data points have correct sizes; 2) query</li><li>values are scalar; 3) query values and table data have the commensurate units; and 4) constants or compile</li><li>time parameters are passed to interpolation and extrapolation argument.</li><li>Argument 1 = [5x1 double]</li><li>Argument 2 = {[273.1500 293.1500 313.1500], 'K'}</li><li>Argument 3 = {[5x3 double], 'F'}</li><li>Argument 4 = [1x1 double]</li><li>Argument 5 = {[1x1 double], 'C'}</li><li>SOC_Table = [5x1 double]</li><li>Temp_Table = {[273.1500 293.1500 313.1500], 'K'}</li><li>C_Table = {[5x3 double], 'F'}</li><li>SOC = [1x1 double]</li><li>T = {[1x1 double], 'C'}</li><li></li><li>I looked at the code but could not tell what was wrong.</li><li>Any ideas?</li></ul>TonyNhttps://se.mathworks.com/matlabcentral/profile/authors/8480954-tonyntag:se.mathworks.com,2005:Question/3323902017-03-28T18:58:17Z2017-03-28T21:37:29ZDetermine UTC Offset for a given Time Zone?<p>I am using an API to bring data into Matlab, and the timestamps are in UNIX time format. It also returns the local time zone for the data. UNIX time is based on UTC, so it convert it into a usable timestamp, I need to consider the UTC offset for the given time zone. The problem is, I can't seem to find a way to input a time zone to Matlab and have it output a UTC offset. I know that this information is available, because you can use tzoffset. But that requires a datetime input.
Which puts me into a kind of catch-22. In order to convert to a datetime, I need the UTC offset. But to get the UTC offset, I need a datetime.</p><p>Is there any function that will tell me the UTC offset if I give it a timezone?</p>peaksixhttps://se.mathworks.com/matlabcentral/profile/authors/9936637-peaksixtag:se.mathworks.com,2005:Question/3324152017-03-28T21:29:19Z2017-03-28T21:29:19ZSetting axis position sometimes requires entering the command twice<p>I have been having a problem when trying to set the Position of a Figure Axis. I will set it the first time with 'Units' set to 'Normalized':</p><p>ax.Position = [0.1 0.15 0.55 0.8];</p><p>The axis is incorrectly resized. If I reenter the same line of code, the axis becomes correctly sized. Regardless of how many times I reenter it, it is the correct size.</p><p>Any ideas? Thanks!</p>jeremyhttps://se.mathworks.com/matlabcentral/profile/authors/5016283-jeremytag:se.mathworks.com,2005:Question/3324122017-03-28T21:07:37Z2017-03-28T21:17:41ZDo you know copy of MATLAB .fig can be edited in MS Word as shape components? <p>It is useful while you are interactively plotting like arc. Altough you can interactively add arrow, circle, text, line, etc. you can not add arc, spline, etc. in figure window of MATLAB.
Have fun!</p>Cemilhttps://se.mathworks.com/matlabcentral/profile/authors/2256880-cemiltag:se.mathworks.com,2005:Question/3323802017-03-28T17:55:55Z2017-03-28T21:17:21ZOut of memory for Blkdiag<p>I have two big matrices ( 5000X329176 and 5000X328658 ) and I want to combine them into one matrix which is in a form of these two in diagonal and all the other elements 0. basically I want blkdiag(A,B).</p><p>The problem is even though I made both these guys in int8 variable type and sparse and they take a small size but for blkdiag function, it needs to make a bigger matrix first ,zeros (5000+5000 X 329176+328658) and this guy is by default made in double which takes a huge amount of Ram.</p><p>I know e.g. zeros(100000,650000) needs 484 GB memory and sparse(zeros(100000,650000)) because of execution order needs the same amount ! however zeros(100000,650000, 'int8') needs 60GB memory which is available.</p><p>Unfortunately, blkdiag does not have this option. So, any idea about solving the problem?</p>Vahid Hematian Dehkordihttps://se.mathworks.com/matlabcentral/profile/authors/7026239-vahid-hematian-dehkorditag:se.mathworks.com,2005:Question/3324032017-03-28T20:22:18Z2017-03-28T21:09:26Z'Global' Variables in a guide GUI<p>I have a GUI guide function, with multiple buttons. I want each button to change a 'global' variable to a different value. How do I go about declaring the variable correctly, and assigning the values correctly?</p>Marcus Blackburnhttps://se.mathworks.com/matlabcentral/profile/authors/8782700-marcus-blackburntag:se.mathworks.com,2005:Question/3324112017-03-28T21:07:23Z2017-03-28T21:07:23ZWhy I have the same neural network results with different weight and bias initiation each time?<p>Hello, anyone can help?</p><p>I am using neural network for prediction purpose, and the network frame is 1 input layer and 1 output layer, I made the hidden layer vary with different hidden neurons set (Hmax=20). And for each H, I set the Ntrials to 10, and in each trial, the network was initiated.</p><p>However, I am getting the same results (same weight and bias) for Ntrials=1:10.</p><p>Thanks!
-Cathy</p><p>Here are some code:</p><p>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p><p>Hmax=20;</p><p>Ntrial=10;</p><p>for i=1:Hmax</p><pre> for j=1:Ntrials </pre><pre> % Create a Fitting Network</pre><pre> hiddenLayerSize = i; % number of hidden neurons in current NN structure</pre><pre> net = fitnet(hiddenLayerSize); </pre><pre> % Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows'};
net.outputs{2}.processFcns = {'removeconstantrows'};</pre><pre> % Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'divideind'; % Divide data by index
net.divideParam.trainInd = trnind;
net.divideParam.testInd = tstind;</pre><pre> % set the transfer function (activation function) for input and
% output layers
net.layers{1}.transferFcn = 'tansig'; % layer 1 corresponds to the hidden layer
net.layers{2}.transferFcn = 'purelin'; % layer 2 corresponds to the output layer
net.layers{1}.initFcn='initwb';
net.trainFcn = 'trainbr'; % Levenberg-Marquardt optimization with Bayesian regularization</pre><pre> net.trainParam.goal=0.01.*var(targets); % usually set this to be 1% of the var(target)
%net.trainParam.goal=0;
net.trainParam.epochs=1000;
net.trainParam.mu_dec=0.8;
net.trainParam.mu_inc=1.5;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'msereg'; % Mean squared error</pre><pre> % Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};</pre><pre> % Train the Network
net=configure(net,inputs,targets);
[net,tr] = train(net,inputs,targets);</pre><pre> % Test the Network
outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs);</pre><pre> % Recalculate Training and Test Performance
trainTargets = targets .* tr.trainMask{1};
testTargets = targets .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs);
testPerformance = perform(net,testTargets,outputs);</pre><pre> % Calculate the R2 Training and Test
H=hiddenLayerSize;
[I,N] = size(inputs); % [8 2519]
[O,N] = size(targets); % [1 2519]
Ntrn = N*0.70;
Ntst = N*0.30;
Ntrneq = Ntrn*1;</pre><pre> %denormalize the output
outputs_real=outputs.*std(sal)+mean(sal);</pre><pre> w1=net.IW{1,1};
w2=net.LW{2,1};
b1=net.b{1};
b2=net.b{2};
end</pre><p>end</p>Cathy Chenhttps://se.mathworks.com/matlabcentral/profile/authors/7680675-cathy-chentag:se.mathworks.com,2005:Question/3324102017-03-28T21:03:32Z2017-03-28T21:03:32ZLoop between dates using the value for that date<p>Hi:</p><p>I want to create a loop but not depending on the position of the value in an array, I want to create it dependent on a certain time:</p><p>I manage to create a timetable with the data I want :</p><img src = "/matlabcentral/answers/uploaded_files/73650/17619046_1504982302847623_1743478613_n.png"><p>Im starting with Matlab and therefore I dont know if it is the best way or not to do this.</p><p>My aim is to do a loop in the following way. For example:</p><pre class="language-matlab">if true
for i= {2015-12-31 10:00}:{2015-12-31}
Pup=UP/1000
Pdown=DOWN/1000
Pelspot=ELSPOT/100
%Im not just dividing in the the code, i will get an output that I will store, but I want the ouput for that certain time)
end
</pre><p>My problem is that I dont know how to tell MATLAB, use the data for this certain date ( now is easy but after I will use a table with 52 000 values were dates are repeated and I want to be sure MATLAB links the DATE with the data in this loop).</p><p>Thanks in advance</p>André Bernal Garcíahttps://se.mathworks.com/matlabcentral/profile/authors/9854639-andre-bernal-garciatag:se.mathworks.com,2005:Question/3320392017-03-26T22:01:58Z2017-03-28T21:03:25ZHow do I change the default axis color and axis label text to black?<p>I want to set the default so that all figures generated henceforth will have black axes and black axis labels. As of now, MATLAB default outputs this really godawful, ugly grey color intead of black and I am really really frickin sick of having to correct this in Illustrator every time. I don't want to have to manually set these values to black every single time I write code for a figure, so how do I change the default?</p><p>Extensive googling on this issue has returned nothing useful on this front. Any help is appreciated.</p>Adam Goldsmithhttps://se.mathworks.com/matlabcentral/profile/authors/6114551-adam-goldsmithtag:se.mathworks.com,2005:Question/3318202017-03-25T00:01:42Z2017-03-28T21:02:33ZHow would I go about plotting "eqn = diff(du) + u == 3* cos(w*t)"<p>In my various attempts to try and plot this function, I keep getting errors.</p><p>ezplot( 'diff(du) + u /( 3* cos(0.5*t))' , [0 15] , u)</p><p>In my latest attempt, I received the error: "Error using sym/ezplot (line 45)
The number of variables must not exceed two when plotting an equation."
(Note that when I changed the 3rd value (u) to t, I received the same error.") The error seems self explanatory, but is there a way I can try to graph this even though it can't go beyond 2 variables.
(Also note that du is declared as the derivative of u)</p>Dinakar Chappahttps://se.mathworks.com/matlabcentral/profile/authors/9606621-dinakar-chappatag:se.mathworks.com,2005:Question/3324082017-03-28T20:43:48Z2017-03-28T20:43:48Zhow to use "hypergeom" on Matlab?<p>How to insert the Hypergeometric function of the type (`2F0`) on Matlab, using "`hypergeom`" command? i have seen the documentation of this command, but i'm not sure that i'm working an a correct manner.</p><p>suppose i want to insert `2F0(a,b;;z)`, how can i use the command? Can i do it like this: `hypergeom(a,b,z)`?</p><p>Can anyone just write me the line to use it?</p>Deema42https://se.mathworks.com/matlabcentral/profile/authors/4722686-deema42tag:se.mathworks.com,2005:Question/3311622017-03-21T23:55:38Z2017-03-28T20:39:57ZHow do I quantify the symmetry of an image?<p>I am interested in quantifying the symmetry in a set of images. In particular, I am interested in symmetry along the vertical and horizontal axes that cut through the middle of the image. (I.e., the two in the example).</p><p>Is there a "best" way to do this in MATLAB?</p>David Sidhuhttps://se.mathworks.com/matlabcentral/profile/authors/3725273-david-sidhutag:se.mathworks.com,2005:Question/3324062017-03-28T20:33:50Z2017-03-28T20:33:50Zinput image size in trainFasterRCNNObjectDetector<p>I try to use trainFasterRCNNObjectDetection in Matlab.
As i understanding, in original faster R-CNN paper, input size of CNN first layer is image size, for example, 256*256.
But in Matlab example;</p><p>https://kr.mathworks.com/help/vision/examples/object-detection-using-faster-r-cnn-deep-learning.html?searchHighlight=fast%20r%20cnn%20object&s_tid=doc_srchtitle
they recommend to use small object size such as 32*32.
I don't understand this part. For applying CNN, input layer has full image size? right?
Pleas help me!</p>younghak shinhttps://se.mathworks.com/matlabcentral/profile/authors/8050917-younghak-shintag:se.mathworks.com,2005:Question/3324052017-03-28T20:33:24Z2017-03-28T20:33:24ZDo you have a 32bit version of lmtools 11.14.0.1?<p>Do you have a 32bit version of lmtools 11.14.0.1?</p>Ed Sykeshttps://se.mathworks.com/matlabcentral/profile/authors/417705-ed-sykestag:se.mathworks.com,2005:Question/3324022017-03-28T20:18:34Z2017-03-28T20:27:24ZTime step with stencil problem<p>Solve the DE: Ut + c Ux = 0, using the following stencil:
o----------o
:
:
:
:
o
is a constant. For this exercise, let c = 0.5.
This is a one-dimensional problem. The initial condition (IC) : U(x,t=0) = exp(-x^0.1) where x refers to the coordinates of cell centers. And boundary condition (BC): U(x=0,t) = 0.8
The stencil suggests this will be an implicit problem; use the Newton-Raphson method. Write a script in MATLAB that solves this problem and plots the solution at tfinal = 1. The spatial domain (x-axis) is [0,1].
Start with writing the fully discrete form of the equation. You are given the solution at t = 0. You will use that as the initial guess for the solution at the next time step and will update your guess until the specified tolerance (1e-5) is met.
Use a grid consisting of 100 cells and a time-step size of 0.001. Write a script that accomplished this above-specified task and plots the initial condition and the final solution (at t = 1) versus x on the same graph.</p><p>Sorry, the stencil looks like an flipped and inverted L (over 1 down 1, if that makes sense) any help would much be appreciated, thanks!!</p>Nick Brownhttps://se.mathworks.com/matlabcentral/profile/authors/9606205-nick-browntag:se.mathworks.com,2005:Question/3324042017-03-28T20:25:16Z2017-03-28T20:25:16ZHow can i detect a (partial) rectangle, use the bottom right corner as a reference point and align my image according to this?<p>Hi, I was wondering whether (well it probably is, but how?) it would be possible to detect the bottom right corner of a paper square I made (which is probably not perfectly square due to my making it by hand) on top of another object. What I want to do is use this paper square as a reference and align the image according to the bottom right corner of the square. I'm quite the Matlab amateur, do you have any help?</p>Jimmy Nhttps://se.mathworks.com/matlabcentral/profile/authors/5893353-jimmy-ntag:se.mathworks.com,2005:Question/1849212015-03-24T15:52:38Z2017-03-28T20:21:57ZHow to Create Libraries in Matlab?<p>OK, I switch gears often between C, Matlab, and Python-so I am really a beginner in the Matlab world. Is there any way, in pure Matlab to create the equivalent of a library? I have several closely related functions that control a piece of hardware. The individual functions are relatively simple, so it seems asinine to have to put each one in a separate m-file. Is there a way I can group them all together? I guess this would be the equivalent of creating a toolbox, but what reading I've done seems to recommend against this approach. In the separate file sceneraio--does Matlab cache the functions in any way, or does the file have to be read from disk every time I call the function? It would seem this would introduce lots of latency.</p>Jimhttps://se.mathworks.com/matlabcentral/profile/authors/5482502-jimtag:se.mathworks.com,2005:Question/3324012017-03-28T20:18:31Z2017-03-28T20:18:31ZFailed to load library libPort_ExecLoader.dll during FPGA-in-the-loop <p>Hi,
I'm trying to do FPGA in the loop through Ethernet with my Xilinx ML505(Virtex-5) Board. Anyway when I want to build the programming file on the final step of filWizard, I got the following error in an external command window:</p><p>Failed to load library libPort_ExecLoader.dll because of the module cannot be found.</p><p>It's reasonable that this is due to some errors in the Xilinx ISE. But I've tested with the ISE alone and it works very well for synthesis, mapping, routing and finally the bit file is also generated (earlier I also got many projects done in ISE so I don't think ISE is having any problem). I don't know now what kind of things go wrong. I'd really appreciate if you could give me some thoughts, thanks!</p><p>My system is Windows 8 with Matlab 2016a and Xilinx ISE 14.4.</p><p>Best regards,
Cy</p>dyyyyylhttps://se.mathworks.com/matlabcentral/profile/authors/6640488-dyyyyyltag:se.mathworks.com,2005:Question/3324002017-03-28T20:02:45Z2017-03-28T20:02:45Zhow can i get mechanical power from block permanent magnet synchronous machine<p>Hello
i use block ''permanent magnet synchronous machine''in simscape library, and i want to get mechanical power from it, i just can got electrical power by this equation Pe=3/2*(Iq*Vq+Id*Vd), i used bus selector to have this parameters Iq,Vq,Id, can someone help me to get mechanical power from it.</p><p>thanks</p><img src = "/matlabcentral/answers/uploaded_files/73647/Sans%20titre.png"><p>Vd</p>amr hayyanihttps://se.mathworks.com/matlabcentral/profile/authors/6781916-amr-hayyanitag:se.mathworks.com,2005:Question/3323892017-03-28T18:56:18Z2017-03-28T19:58:29ZDifferences between the executing environment of mex functions and s functions<p>Hi all,</p><p>I have a problem that has stumped me for nearly two weeks. I have a library that presents a C interface, for the purpose of sending Google protobuf serial information across a network socket. The library works great when called via a C driver program. It also works great when I encapsulate it as a MEX file. And it reliably segfaults when called from a type 2 S function file (but only on Linux - calling it on a Mac as an S function also works beautifully).</p><p>The only information from the stack trace is that the segfault occurs in libstdc++.so.6, in a library call that is name mangled as "resizeEmc". It seems to occur even before any of the code in the S function is actually executed - it's happening during the load or library initialization process. And it happens even if I comment out all of the code in the S Function that actually calls the library code; all that is required for the crash is for there to be a linker dependency on the library in the compiled .mexa64 file.</p><p>So, my question: what is the difference between the executing environment of a plain vanilla MEX file and a Simulink S Function? Does one handle dynamically allocated memory, or global static variables in the library, or something, differently from the other? Is there a difference in how dynamic library dependencies get resolved?</p>Glenhttps://se.mathworks.com/matlabcentral/profile/authors/31653-glentag:se.mathworks.com,2005:Question/3318302017-03-25T03:52:10Z2017-03-28T19:56:36ZHow to use trainpso to train a neural network model<p>function [net, tr] = trainpso(net, tr, trainV, valV, testV, varargin)</p><p>the trainpso is shown like this, how to input the data so that i can use trainpso to train a neural network model?</p>jiabo hehttps://se.mathworks.com/matlabcentral/profile/authors/9246647-jiabo-hetag:se.mathworks.com,2005:Question/2979222016-08-01T09:31:46Z2017-03-28T19:55:38ZHow can I change the temperature unit for sensor BMP180 unsing Raspberry PI?<img src = "/matlabcentral/answers/uploaded_files/57071/setTemperatureUnit.JPG"><p>I started working with the temperature sensor BMP180 connected to a Raspberry Pi 2. I'm using the Raspberry toolbox so I created a raspi object called mypi and a bmp object with</p><pre class="language-matlab">bmp = raspi.internal.bmp180(mypi, 'i2c-1')
</pre><p>now I can go on with</p><pre class="language-matlab">temperature = readTemperature(bmp)
</pre><p>but now I want to change the temperature unit from "Celsius" to "Kelvin". How can I do that? I found</p><pre class="language-matlab">set.TemperatureUnit(obj, value)
</pre><p>in the bmp180.m but can not run it successfully. The image showes what I have tried</p>Susanne Maihttps://se.mathworks.com/matlabcentral/profile/authors/6562509-susanne-maitag:se.mathworks.com,2005:Question/3323992017-03-28T19:54:35Z2017-03-28T19:54:35ZSort the vector in a specific order<p>I have a problem sorting the vector,
I already use the bubblesort but it dosen't work,
I need to fill the centroids from the image from up to down and from left to right
can anyone help me
%%</p><img src = "/matlabcentral/answers/uploaded_files/73646/PICT0006.JPG"><pre class="language-matlab">%%get de image from the file
[nombre, dire]=uigetfile({'*.jpg;*.bmp;*;*.tiff','Imágenes';...
'*.jpg','JPEG (*.jpg)';'*.bmp', 'BITMAP (*.bmp)';}...
,'selecciona imagen','C:\Users\Roguegear\Documents\Escuela\Cuatrimestre 10\Vision');
imcal1=imread( fullfile(dire,nombre));
figure
imshow(imcal1)
assignin('base','imcal1',imcal1);
%% convert to binary the image
img_g=rgb2gray(imcal1);
figure
imshow(img_g);
thresh= graythresh(img_g);
BW=im2bw(img_g,0.5);
figure
imshow(BW)
</pre><pre> BW=not(BW);
%BW=BW.*(masc)
figure
imshow(BW)
%%
%get the centroids
BW=bwareaopen(BW,10);
h=ones(2,2);
BW=imerode(BW,h);
figure
imshow(BW)
centroides=regionprops(BW,'centroid');
kk=size(centroides);
centroideso=centroides;
%%
%sort centroides
field ='Centroid';
for k=1:kk(1)
cen=centroideso(k).Centroid;
try
valuex=[valuex;cen(1)];
valuey=[valuey;cen(2)];
valueh=[valueh;sqrt(((cen(1))^2)+((cen(2))^2)) k];
catch
valuex=cen(1);
valuey=cen(2);
valueh=[sqrt(((cen(1))^2)+((cen(2))^2)) k];
end
end
%Ordenar H
n=kk(1);
svc=length(valueh);
for p=1:svc
ae1=valueh(p,1);
ae2=valueh(p,2);
valuec(p,1)={[ae1 ae2]};
end
centroideso=struct(field,valuec);
for i=1:n
for j=1:n-i
ceno=valuec(j);
cena=valuec(j+1);
ceno=ceno(1);
cena=cena(1);
if ceno>cena
aux=valuec(j);
valuec(j)=valuec(j+1);
valuec(j+1)=aux;
end
end
end
% valuef=cat(2,valuex,valuey);
% svc=length(valuef);
% for p=1:svc
% ae1=valuef(p,1);
% ae2=valuef(p,2);
% valuec(p,1)={[ae1 ae2]};
% end
% centroideso=struct(field,valuec);</pre>Guillermo Gutiérrezhttps://se.mathworks.com/matlabcentral/profile/authors/6627663-guillermo-gutierreztag:se.mathworks.com,2005:Question/3323982017-03-28T19:49:35Z2017-03-28T19:49:35ZHow can I select a specific region of a color diagram?<p>Hi;
I have a gamma-corrected RGB matrix, obtained by computing the chromaticity matrices to the RGB 709 transformation matrix. I did the following to display the color diagram:</p><p>img = Corr_rgb;</p><pre> figure;
image([0:.005:1],[0:.005:1],img);
axis('xy'); </pre><p>where Corr_rgb is the gamma-corrected RGB matrix. Now I want to insert the chromaticity diagram to show the colors inside the RGB 709 gamut. I know how to insert the chromaticity diagram into the color diagram, but how can I make the plot to show only the colors inside the RGB 709 gamut so I can have a color-filled triangle as a final result?</p>Agustinhttps://se.mathworks.com/matlabcentral/profile/authors/5558144-agustin