https://it.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-06-19T14:44:05Ztag:it.mathworks.com,2005:Question/8602602021-06-19T11:56:40Z2021-06-19T14:44:05ZDraw a gradient circle within a circleI want to code a gradient circle within a circle like shown in the diagram. Any help will be appreciated. Sajjad Ahmad Khanhttps://it.mathworks.com/matlabcentral/profile/authors/15327367tag:it.mathworks.com,2005:Question/8603552021-06-19T14:42:58Z2021-06-19T14:42:58ZAfter applying 'Pause on NAN or Inf of run option I am gettingt error message.NaN/Inf breakpoint hit for ode45.m on line 256.
256 rh = norm(f0 ./ max(abs(y),threshold),inf) / (0.8 * rtol^pow);
I am getting above error after executing following code after applying 'Pause on NAN or Inf of run option. and when i simply hit run option then program is just running without any output.
clc
close all
clear
rng(0,'twister');
n=input('Number of Values Required :');
a1 = 0.0003;
b1 = 0;
k1 = (1*a1)*randn(n,1)+b1; % epsilonY
a2 = 0.0003;
b2 = 0;
k2 = (1*a2)*randn(n,1)+b2; % epsilonz
a3 = 0.03;
b3 = 0;
k3 = (1*a3)*randn(n,1)+b3; % plc
a4 = pi;
b4 = 0;
k4 = (1*a4)*randn(n,1)+b4; % omegaPL
a5 = 0.04*pi/180;
b5 = 0;
k5 = (1*a5)*randn(n,1)+b5; % phi0
a6 = 0.04*pi/180;
b6 = 0;
k6 = (1*a6)*randn(n,1)+b6; % theta0
a7 = 0.04*pi/180;
b7 = 0;
k7 = (1*a7)*randn(n,1)+b7; % psi0
a8 = 0.73;
b8 = 7.3;
k8 = (1*a8)*randn(n,1)+b8; % mp
a9 = 0.0005298;
b9 = 0.005298;
k9 = (1*a9)*randn(n,1)+b9; % ixx
a10 = 0.00835;
b10 = 0.0835;
k10 = (1*a10)*randn(n,1)+b10; % izz
a11 = 0.15;
b11 = 0;
k11 = (1*a11)*randn(n,1)+b11; % eta
a12 = 0.0004675;
b12 = 0.004675;
k12 = (1*a12)*randn(n,1)+b12; % Asr
a13 = 0.00293;
b13 = 0.0293;
k13 = (1*a13)*randn(n,1)+b13; % ldb
a14 = 0.007776;
b14 = 0.07776;
k14 = (1*a14)*randn(n,1)+b14; % ldbcg
a15 = 0.0098;
b15 = 0.098;
k15 = (1*a15)*randn(n,1)+b15; % lsrcg
a16 = 0.015864;
b16 = 0.15864;
k16 = (1*a16)*randn(n,1)+b16; % lcbcg
a17 = 0.0000235;
b17 = 0.000235;
k17 = (1*a17)*randn(n,1)+b17; % delta0
%% Prepration
for i=1:n
tic
global l_barrel texit mp ixx izz eta Ns Db Ab Asr ldb ldbcg lsrcg mudb kdb alpha delta0 pcData c p0 gamma lcbcg fxc epsilonY epsilonZ plc omegaPL
l_barrel= 5.14275; % Shot Travel
mp = k8(i,1); % Mass of shot
ixx = k9(i,1); % Moment of Inertia about axis of shot
izz = k10(i,1); % Lateral Moment of Inertia about
eta = k11(i,1); % Band Slip parameter
Ns = 18; % Rifling Twist
Db = 0.12; % Bore Diameter
Ab = (pi/4)*Db^2; % Bore Area
Asr = k12(i,1); % Projected area sabot rear for lateral pressure acting
ldb = k13(i,1); % Length of Driving Band
ldbcg = k14(i,1); % Length between DB Rear to CG of Shot
lsrcg = k15(i,1); % Length between sabot projected area to CG of Shot
lcbcg = k16(i,1); % Length between CB to CG of Shot
mudb = 0.1; % Friction Coefficient
alpha = 5.71*pi/180; % Friction angle
delta0 = k17(i,1); % DB compression
epsilonY = k1(i,1); % CG eccentricity in y
epsilonZ = k2(i,1); % CG eccentricity in z
plc = k3(i,1); % 0.02; % Lateral Pressure
omegaPL = k4(i,1); %pi; % Angular orientation of lateral pressure
E = 3.1e9; % DB Young's Modulous
nu = 0.4; % DB Poission's Ratio
ro = 60e-3; %52.5e-3; % Outer Radius of DB
ri = 52.5e-3;%ro-3.8675e-3; % Inner Radius of DB
Adb = pi*ro*ldb; % Half Circumferential Area of DB
kdb = E*(((1+nu)*ro^2+(1-nu)*ri^2)/((1-nu^2)*ro*(ro^2-ri^2)))*Adb; % Stiffness of DB
fxc = -2*mudb*kdb*delta0*cos(alpha); % Force in x axis due to DB
c = 8.5; % Charge Mass
p0 = 101325; % Atmospheric Pressure
gamma = 1.23; % Specific Heat Ratio
pcData = xlsread('chamber_pressure.xlsx');
timespan=size(pcData);
texit=pcData(timespan(1),1)/1000;
x0 = 0; % Initial Position of Shot CG
y0 = 0; %0.00005;
z0 = 0;
phi0 = k5(i,1);
theta0 = k6(i,1); %0.02*pi/180;
psi0 = k7(i,1);
dx0 = 0; % Initial velocity of Shot CG
dy0 = 0;
dz0 = 0;
dphi0 = 0;
dtheta0 = 0;
dpsi0 = 0;
initialCond = [x0 y0 z0 phi0 theta0 psi0 dx0 dy0 dz0 dphi0 dtheta0 dpsi0];
Impact_Count = 0;
loop_Count = 0;
T = [];
PosVelos = [];
Rimp = [];
t = 0.009;
dt = 0.1e-6;
Xcg = 0;
%% Simulation
while t<=texit && Xcg<=l_barrel
loop_Count = loop_Count + 1;
T2 = t:dt:t+0.001;
Rates_ODE45 = @(T,X) Rates_Fun(T,X);
options = odeset('Events',@Impact_Check);
[T2, X] = ode45(Rates_ODE45,T2,initialCond,options);
l = length(T2);
Rimp2 = zeros(size(T2));
x = X(l,1);
y = X(l,2);
z = X(l,3);
phi = X(l,4);
theta = X(l,5);
psi = X(l,6);
dx = X(l,7);
dy = X(l,8);
dz = X(l,9);
dphi = X(l,10);
dtheta = X(l,11);
dpsi = X(l,12);
yCB = y + lcbcg*psi;
zCB = z - lcbcg*theta;
r = sqrt(yCB^2 + zCB^2);
omegaImp = atan2(yCB,zCB);
vImp = (dy + lcbcg*dpsi)*sin(omegaImp) + (dz - lcbcg*dtheta)*cos(omegaImp);
if ((r>=0.0001) &&( vImp>0))
Impact_Count = Impact_Count+1;
RImp = 2*vImp/(1/mp + lcbcg^2/izz);
X(l+1,:) = [x y z phi theta psi dx (dy-RImp*sin(omegaImp)/mp) (dz-RImp*cos(omegaImp)/mp) dphi (dtheta+RImp*lcbcg*cos(omegaImp)/izz) (dpsi-RImp*lcbcg*sin(omegaImp)/izz)];
T2(l+1) = T2(l);
Rimp2(l+1) = RImp;
end
t = T2(length(T2));
initialCond = X(length(T2),:);
Xcg = X(length(T2),1);
T = [T;T2];
PosVelos = [PosVelos;X];
Rimp = [Rimp;Rimp2];
end
disp('loop execution count')
disp(loop_Count)
disp('impact count')
disp(Impact_Count)
disp('time to simulation')
disp(toc)
%% Post Processing
x = PosVelos(:,1);
y = PosVelos(:,2);
z = PosVelos(:,3);
phi = PosVelos(:,4);
theta = PosVelos(:,5);
psi = PosVelos(:,6);
dx = PosVelos(:,7);
dy = PosVelos(:,8);
dz = PosVelos(:,9);
dphi = PosVelos(:,10);
dtheta = PosVelos(:,11);
dpsi = PosVelos(:,12);
Pc = 1000000*interp1(pcData(:,1)/1000,pcData(:,2),T,'pchip');
Pb = Pc/(1+c/(2*mp));
Pa = 0;
Pl = plc*Pb;
fxp = Ab*(Pb-Pa);
fyp = Ab*(Pb-Pa).*psi + Asr*Pl.*sin(omegaPL);
fzp = Ab*(Pb-Pa).*theta + Asr*Pl.*cos(omegaPL);
fyc = kdb*(((ldbcg-0.5*ldb)*psi-y)+mudb*sin(alpha)*((ldbcg-0.5*ldb)*theta+z));
fzc = kdb*((-(ldbcg-0.5*ldb)*theta-z)-mudb*sin(alpha)*((ldbcg-0.5*ldb)*psi+y));
ddx = (fxp+fxc)/mp;
ddy = (fyp+fyc)/mp;
ddz = (fzp+fzc)/mp;
ddphi = 2*pi*ddx*eta/(Ns*Db);
Myp = -Ab*((Pb-Pa).*(z+epsilonZ)-(Pb*ldbcg-Pa*(ldbcg-ldb)).*theta)+Asr*Pl.*cos(omegaPL)*lsrcg;
Mzp = -Ab*((Pb-Pa).*(y+epsilonY)+(Pb*ldbcg-Pa*(ldbcg-ldb)).*psi)-Asr*Pl.*sin(omegaPL)*lsrcg;
Myc = -(z+epsilonZ).*fxc + (ldbcg-0.5*ldb)*fzc - mudb*kdb*Db/2*cos(alpha)*(z-(ldbcg-0.5*ldb)*psi) + kdb*ldb^2*(theta-psi*mudb*cos(alpha))/12;
Mzc = (y+epsilonY).*fxc - (ldbcg-0.5*ldb)*fyc - mudb*kdb*Db/2*cos(alpha)*(y-(ldbcg-0.5*ldb)*psi) - kdb*ldb^2*(psi+theta*mudb*cos(alpha))/12;
ddtheta = (Myp + Myc + (izz-ixx)*dphi.*(dpsi-theta.*dphi))/izz + dphi.*dpsi+ddphi.*psi;
ddpsi = (Mzp + Mzc + (ixx-izz)*dphi.*(dtheta+psi.*dphi))/izz - dphi.*dtheta+ddphi.*theta;
yCB = y + lcbcg*psi;
zCB = z - lcbcg*theta;
r = sqrt(yCB.^2 + zCB.^2);
omegaImp = atan2(yCB,zCB);
vImp = (dy + lcbcg*dpsi).*sin(omegaImp) + (dz - lcbcg*dtheta).*cos(omegaImp);
outputparameters=ddpsi;
filename = sprintf('Outdata%04d.xlsx', i);
xlswrite(fullfile('D:\Project\T', filename),outputparameters)
disp('time to postprocess and write output file')
disp(toc)
disp('Run Completed')
CBtheta=0:360;
yyCB=0.0001*sind(CBtheta);
xxCB=0.0001*cosd(CBtheta);
end
Please solve this issueShrinivas Kalehttps://it.mathworks.com/matlabcentral/profile/authors/17376178tag:it.mathworks.com,2005:Question/8603452021-06-19T14:28:54Z2021-06-19T14:42:34ZDefine relationship between variables in an equationAn equation has two variables d and t.
eqn = ((t - 21/2)*(d/2 - (20898604612049288806642049279907*t)/70957580590508366543483568128000 + 471612538725450581/36028797018963968)*(d + (20898604612049288806642049279907*t)/35478790295254183271741784064000 - 471612538725450581/18014398509481984) - ((41181014215700959230589300565923*t)/53218185442881274907612676096000 - 253280971625720775/9007199254740992)*(t/2 - 21/4)*((4992772075141567*t)/9007199254740992 - 104848213577972907/18014398509481984))/((t - 21/2)*(d + (20898604612049288806642049279907*t)/35478790295254183271741784064000 - 471612538725450581/18014398509481984) + (t/2 - 21/4)*((4992772075141567*t)/9007199254740992 - 104848213577972907/18014398509481984)) + (((41181014215700959230589300565923*t)/53218185442881274907612676096000 - 253280971625720775/9007199254740992)*(t/2 - 21/4)*((4992772075141567*t)/9007199254740992 - 104848213577972907/18014398509481984) - (t - 21/2)*(d/2 - (20898604612049288806642049279907*t)/70957580590508366543483568128000 + 471612538725450581/36028797018963968)*(d + (20898604612049288806642049279907*t)/35478790295254183271741784064000 - 471612538725450581/18014398509481984) + 39208413340930135/8796093022208)/((t - 21/2)*(d + (20898604612049288806642049279907*t)/35478790295254183271741784064000 - 471612538725450581/18014398509481984) + (t/2 - 21/4)*((4992772075141567*t)/9007199254740992 - 104848213577972907/18014398509481984) - 5373422634669521/17592186044416) == 0;
and I want to find the relationship between them like d=f(t).
How to define f(t)?lyhttps://it.mathworks.com/matlabcentral/profile/authors/6006563tag:it.mathworks.com,2005:Question/5271792020-05-19T04:00:00Z2021-06-19T14:40:29ZWhy do I receive "terminate called after throwing an instance of '(anonymous namespace)::DisplayError' what(): No display available. Aborted (core dumped)" when installing MATLAB or other MathWorks Products on Linux?Why do I receive the following error when attempting to install MATLAB or other MathWorks Products on Linux?
terminate called after throwing an instance of '(anonymous namespace)::DisplayError'
what(): No display available.
Aborted (core dumped)
MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813tag:it.mathworks.com,2005:Question/8599102021-06-18T18:44:43Z2021-06-19T14:39:03ZHow to make an ENVI header file."?I am trying to use the hypercube function to read a hyperspectral image but it gives me this error.
The error
Error using enviinfo (line 86)
Input file must be a ENVI header file.
The code Line:-
hcube = hypercube('indian_pines.dat');
so can you please tell me how to fix it or tell me how can I make it an ENVI header file?
Thank youuuMohamed Yasserhttps://it.mathworks.com/matlabcentral/profile/authors/22814263tag:it.mathworks.com,2005:Question/8603502021-06-19T14:38:42Z2021-06-19T14:38:42ZHow many dimensions do I need?Duc Anh Nguyenhttps://it.mathworks.com/matlabcentral/profile/authors/22849281tag:it.mathworks.com,2005:Question/8593752021-06-18T09:04:03Z2021-06-19T14:38:38ZError loading matlabprefs.matHallo,
there is an error:
MATLAB:load:notBinaryFile
Unable to read MAT-file /home/myUser/.matlab/R2021a/matlabprefs.mat. Not a binary MAT-file. Try load -ASCII to read as text.
sometimes (this is not reproducible) it pops up after rebooting Matlab:
Warning: Initializing MATLAB Graphics failed.
This indicates a potentially serious problem in your MATLAB setup, which should be resolved as soon as possible. Error detected was:
MATLAB:load:unableToReadMatFile
Unable to read MAT-file /home/myUser/.matlab/R2021a/matlabprefs.mat. File might be corrupt.
> In hgrc (line 163)
In matlab.graphics.internal.initialize (line 15)
Some pages (e.g. https://www.mathworks.com/matlabcentral/answers/364986-matlab-error-graphic) recommend deleting matlabprefs.mat. However, if I do, the error pops up again.
I also deleted full ~/.matlab folder. The error was gone for a couple of hours. Now, it reappears.
Does anybody know a persistent solution?
ThanksAndreas Schwagerhttps://it.mathworks.com/matlabcentral/profile/authors/1429277tag:it.mathworks.com,2005:Question/8601502021-06-19T07:20:08Z2021-06-19T14:37:55ZHow can I plot (y vs t) and (z vs t) in one graph?z=4;y=2;
h=0.1;
t0=0;
tn=0.4;
y=2;
fprintf('x y z\n');
for t=t0:h:tn
dy=@(y,t) -2*y+4*exp(-t);
dz=@(y,z) -(y*z^2)/3;
ynew=y+dy(y,t)*h;
znew=z+dz(y,z)*h;
fprintf('%2.4f %2.4f %2.4f \n',t,ynew,znew);
z=znew;y=ynew;
endItqan Ismailhttps://it.mathworks.com/matlabcentral/profile/authors/16411116tag:it.mathworks.com,2005:Question/8602902021-06-19T12:57:53Z2021-06-19T14:33:59ZHow to extrapolate a level curve form a 3D plot of a 2-variables function?Hi guys! I've a plot of a 3D function of 2 variables and I'm interested into extrapolating the curve that corresponds to CM=0 and the I want to plot this level curve in another figure.
Here there is the code used to obtain the plot:
figure(3);
CM_plot=reshape(CM,[length(Alfa),length(Mach)]);
surf(Mach,Alfa,CM_plot);
xlabel('$M$','Interpreter','Latex','Fontsize',15 ,'FontAngle','italic');
ylabel('$\alpha$ $(deg)$','Interpreter','Latex','Fontsize',15 ,'FontAngle','italic');
zlabel('$C_{M}$','Interpreter','Latex','Fontsize',15 ,'FontAngle','italic')
set(gca,'YDir','reverse')
set(get(gca,'ZLabel'),'Rotation',0,'Position',[0.6 -22.5 0.115]);
view([-114.52 20.44]);
Can you hep me?Giuseppehttps://it.mathworks.com/matlabcentral/profile/authors/9702519tag:it.mathworks.com,2005:Question/8602952021-06-19T13:07:32Z2021-06-19T14:31:23ZHow can I change graph label linearly to a time intervalI have datasets that correspond to a certain time of simulations. When I plot these datasets, the x labels, of course, shows the length of the data. I changed it with
xticks([0 1000 2000 3000])
xticklabels({'0','10','20','30'})
Which is not very accurate, and wanted to know if there is a way of making the length of my data equals to 'x' nanoseconds and then adjust the ticks and labels accordingly.Dussan Radonichhttps://it.mathworks.com/matlabcentral/profile/authors/19669589tag:it.mathworks.com,2005:Question/8602802021-06-19T12:51:40Z2021-06-19T14:30:55ZFind very small zeros of a polynomialI have to find the zeros of the derivative of this function :
V(r) = a_Constant*( (0.5/r)^12 - (0.5/r)^6);
Then I'd do diff(V(r),r). And finally, do a findzeros of this answer in a specific interval.
The problem is that the answer are so small, that matlab is returning zero for the roots of the derivative. Is there a way of doing this process and to be able to find all the zeros within a specific intervall.Zerohttps://it.mathworks.com/matlabcentral/profile/authors/17539403tag:it.mathworks.com,2005:Question/8600902021-06-19T05:24:55Z2021-06-19T14:30:24ZHow to batch processing the answers from MATLAB to ExcelGreetings. I have several questions that i want to ask for you guys.
How to import data from Excel? I used to utilise the function readmatrix() to read the data for particular column.
How to use the data that I imported from Excel to perform batch processing? For instance, I've already imported years, months and days from Excel to MATLAB, now I need to perform calculations in MATLAB, and export every answers back to Excel after I got every answers by using formula.
I think that the loop function would be involved in this case.
Here is a simple example:
I have many data in Excel:
Year Month Day
2001 1 1
2002 2 2
2003 3 3
I want to import these data above to MATLAB.
After that, I want to use these data to perform several calculation by using the formulas below:
Total=year+month+day
Something=Total-somethingelse
Once I get the answer which is 'something', I want to send back the result back to Excel. In this simple example, I will get 3 answers. I think the results will be shown like this below:
Something
2003
2006
2009
I think the loop function would be appeared in the coding. I have been searching this issue such a long time, please help me, and thanks for spending time to read and solve this question. Have a great day!Hong Wei Tanghttps://it.mathworks.com/matlabcentral/profile/authors/22846582tag:it.mathworks.com,2005:Question/8601302021-06-19T06:29:04Z2021-06-19T14:28:03ZCan any one help me on gaining a correct sketch in regard to this code???clear, clc;
phi=3411;
beta=0.0167;
omega=0.24;
delta=0.0056;
md=8.2192*10^(-5);
mu=1.3699*10^(-5);
tau=0.7;
alpa=0.005;
h=0.1;
alpha=[0.5; 0.6; 0.7; 1.0];
t=0:h:1000;
n=length(t);
m=length(alpha);
solS=[]; solV=[]; solI=[]; solR=[];solN=[];
for k=1:m
S=zeros(n, 1); V=S; I=S; R=S;N=S;
V(1)=0; I(1)=1152283; R(1)=778*10^(3); S(1)=8.105*10^(7);N(1)=83;
for i = 1 : n-1
S(i+1)=S(i)+(h^alpha(k)/gamma(alpha(k)+1))*((phi+omega*V(i)-(alpa+(1-alpa)*beta*I(i)/(S(i)+I(i)+V(i)+R(i))+mu))*S(i));
V(i+1)=V(i)+(h^alpha(k)/gamma(alpha(k)+1))*(alpa*S(i)-(omega+tau+mu)*V(i));
I(i+1)=I(i)+(h^alpha(k)/gamma(alpha(k)+1))*((1-alpa)*beta*I(i)*S(i)/(S(i)+I(i)+V(i)+R(i))-(delta+md+mu)*I(i));
R(i+1)=R(i)+(h^alpha(k)/gamma(alpha(k)+1))*(delta*I(i)+tau*V(i)-mu*R(i));
end
solS(:, k) = S(:); solV(:, k) = V(:); solI(:, k) = I(:); solR(:, k) = R(:); solN(:, k) = N(:);
end
plot (t,solI(:,1),'r',t, solI(:,2),'g',t,solI(:,3),'k', t, solI(:,4),'b','LineWidth',2);
xlabel ('Time (day)'), ylabel('Infected'), title('Size of the Infected for diferent values of \alpha');
legend ('\alpha=0.5','\alpha=0.6','\alpha=0.7','\alpha=1.0')Iqbal Batihahttps://it.mathworks.com/matlabcentral/profile/authors/11694039tag:it.mathworks.com,2005:Question/8603402021-06-19T14:22:50Z2021-06-19T14:22:50ZUpdating values in a 2x2 matrix , taking values from result of an iterative operation.So I want to create a 2x2 matrix. Then I want its element [1,1] to stor values from result of an operation (function) and the element [1,2] to store results of another operations. In short, the values will keep changing as the variable 't' changes . (since i will be using 't' in the operation.). My formula is below :
t = (1:30) #values of 't' from 1 to 30
p1 = 1-(5/6).^t #need to store this result at position [1,1] of matrix
p2= 1-p1 #Need to store this value at position [1,2] of matrix
The values for other two positions of matrix [2,1] and [2,2] should remain constant (0 and 1 respectively).
I don't know how to implement this.Umair Ahmedhttps://it.mathworks.com/matlabcentral/profile/authors/22817841tag:it.mathworks.com,2005:Question/8603352021-06-19T14:22:14Z2021-06-19T14:22:14ZHow to highlight segment signal line in Simulink?Hi all,
I use find_system function for find all signal in untitled model as:
>> lines = find_system('untitled','FindAll','on','type','line')
lines =
195.0822
196.0822
194.0822
204.0823
193.0822
Now I want to highlight 1 of segment as:
But, when I use hilite_system function, it alway highlight all of segments.
hilite_system(lines(i)) % i = from 1 to 5
So, how can I highlight 1 segment only?
Thank you so much.galaxyhttps://it.mathworks.com/matlabcentral/profile/authors/15063927tag:it.mathworks.com,2005:Question/8601402021-06-19T06:56:44Z2021-06-19T14:09:29ZIssue with using loopI have 3 dimensional matrix, 135*129*43099. 43099 being the daily rainfall value for 118 years(1901 to 2018). I intend to convert this daily rainfall value to monthly rainfall value, resulting matrix 135*129*1416.
For this I created a matrix of size 1416*5. Each row representing each month for 118 years. First column is year, second column is month, third column is number of number of days in a month (irrevelant and not used here), fourth and fifth column is the index. Gilmpse of such matrix's small portion is below.
Name of matrix: 'statarrayD'
1901 1 31 1 31
1901 2 28 32 59
1901 3 31 60 90
1901 4 30 91 120
1901 5 31 121 151
1901 6 30 152 181
Here is the deal, I want to add 1st to 31st value of those 43099 values to place it into a first row, similarly for second row, i want to add 32nd to 59th value of 43099 values. This way i would have 1416 rows in the resulting matrix, formed as a result of adding those 43099 values, which is named MRain here.
Code:
MRain=NaN(135,129,1416);
x=1;
for i=1:1416
MRT=NaN(135,129,43099);
min=statarrayD(i,4);
max=statarrayD(i,5);
MRT(:,:,min:max)=temp(:,:,min:max);
MRain(:,:,x)=sum(MRT,3);
x=x+1;
end
MRT is the temporary matrix that would return monthly values. Say when value of i=1 then, it would return the 1st to 31st rainfall values, remaining being NaN. min and max would return 1 and 31 respectively. min and max are basically 4th and 5th column of the matrix shown above. I am using sum function to add the MRain montly values, to get one value for each month.
This code seems to work perfectly without loop, when i use the numerical value like 1, 2, 3 instead of value of i, like code shown below. But returns NaN value for entire MRain matrix with used with loop. I am missing something in the loop.
%test%
MRest=NaN(135,129,1416);
MRTest=NaN(135,129,35);
min=statarrayD(1,4);
max=statarrayD(1,5);
MRTest=temp(:,:,min:max);
MRest(:,:,1)=sum(MRTest,3);Suman Dhamalahttps://it.mathworks.com/matlabcentral/profile/authors/19261521tag:it.mathworks.com,2005:Question/8598402021-06-18T17:30:48Z2021-06-19T14:08:46ZHow to change the Image colour of ones and zeros to white and black The mage has 50 x 100 points (vertical x horizontal dimension). Each point can be zero or one, where zero = white colour and one = black colour.
I tried this
B = randi([0 1],50, 100);
imagesc(B)
The output image is represented with yellow and blue but I want it to be black and white.
Akakan-Abasi Okonhttps://it.mathworks.com/matlabcentral/profile/authors/20263718tag:it.mathworks.com,2005:Question/8581452021-06-16T20:47:11Z2021-06-19T14:06:38ZAttaching a simulink model, can anyone tell the equations governing ?Varun Nairhttps://it.mathworks.com/matlabcentral/profile/authors/16457153tag:it.mathworks.com,2005:Question/8603302021-06-19T14:05:04Z2021-06-19T14:05:04Ztwo colormap in one figureHow do i plot two colormap in on figure with following codes
x=400:.1:750;
x=[x];
y=0:0.1:1;
y=[y];
z=0:(1/3500):1;
z=repmat(z,11,1);
pcolor(x,y,z);
shading interp;
colormap('jet')
xlim([545 730])
hold on
z1=load('H.txt');
z1=z1(:,4);
z1=z1.';
z1=repmat(z1,11,1) ;
A=545:1:730;
x1=[A];
y1=[0:.1:1];
pcolor(x1,y1,z1)
shading interp
colormap('gray')
xlabel('wavelength(nm)');
baljit singhhttps://it.mathworks.com/matlabcentral/profile/authors/9214825tag:it.mathworks.com,2005:Question/8603252021-06-19T14:03:42Z2021-06-19T14:03:42ZPlotting a shapefile.I want to plot shapefile. Shapefile is polygon. I used following code.
India=shaperead('india.shp');
longitude=ncread(filename,'lon');
latitude=ncread(filename,'lat');
mymap=pcolor(longitude,latitude,MeanJJASRain');
mymap.EdgeAlpha=0;
hold on
colorbar
caxis('auto');
title('Mean (1901-2018');
cmp=colormap;
cmp=flipud(cmp);
colormap(cmp);
mapshow(India);
hold off
Ignoring the rest, mapshow command plots the shapefile, but the shapefile is soild and filled inside. Because of this the plot from pcolor is hidden. How to make the shapefile transparent and plot only the outline?Suman Dhamalahttps://it.mathworks.com/matlabcentral/profile/authors/19261521tag:it.mathworks.com,2005:Question/8600152021-06-18T22:30:58Z2021-06-19T14:02:40ZEliminate string from vectorHi, i created a vector containing 963 nc file. The problem is that some of them are the same but from two different version and i want to delete the previous version. For example, how can i eliminate row 844, 846 and 848 from my vector? Thanks allGiacomo Abrardohttps://it.mathworks.com/matlabcentral/profile/authors/13995940tag:it.mathworks.com,2005:Question/8600602021-06-19T01:37:47Z2021-06-19T14:02:16ZHow to know what toolboxes and or functions my code in appdesigner is using?I have a fairly extensive GUI in appdesigner. I have downloaded different open source functions that I'll often call in the code. However, it's gotten to a point where I'm not sure which functions I'm calling outside of what's available in Matlab itself. Is there a way to know which functions my code uses that is available in the path?Dc215905https://it.mathworks.com/matlabcentral/profile/authors/11207461tag:it.mathworks.com,2005:Question/8602752021-06-19T12:34:31Z2021-06-19T14:01:57ZHow to delete empty categories in labels in AudioDataStore?Hello,
I have this problem: I created a DataAudioStore for some files with emotion labels.
RavdnessDataStore.Labels would look like this:
Original has 8 emotion, so summary would look like this
Then I wanted to create some subdatastores (for other use) with only two emotion
emotion1 = categorical("Angry");
emotion2= categorical("Calm");
RavdnessDataStore = subset(RavdnessDataStore,RavdnessDataStore.Labels.Emotion==emotion1 | RavdnessDataStore.Labels.Emotion==emotion2);
And it would give my what I want (only files with those two emotion), but when I look up summary it would be like this:
I dont want 8 categories, but only two (later it cause me some co problem with clasification, because program sees eight categories not two).
Nothing I do to try to remove those empty categories seems to work.
I would appreciate any help!Karolina Cichahttps://it.mathworks.com/matlabcentral/profile/authors/17681476tag:it.mathworks.com,2005:Question/492852012-09-27T21:26:17Z2021-06-19T13:59:53ZFull duplex AM transmitter and receiver using the USRP N210Hello,
I’m new working with the USRP N210 and I’m trying to make a full duplex AM modulator, but it doesn’t work. I already tested the FRS GMRSD demo and its working transmitting from port RF1 and receiving by the RF2.
I tested the transmitter and the receiver using 2 radios and I receive my wave, but I need both in the same schema Simulink. I don't understand why it doesn't work if I'm sending just a 150HZ signal modulated by a 1.042GHZ carrier.
I hope someone could help me.
Tks.Laura Hernandezhttps://it.mathworks.com/matlabcentral/profile/authors/3494054tag:it.mathworks.com,2005:Question/8603202021-06-19T13:59:30Z2021-06-19T13:59:30Zhow do i generate simulink model with matlab code available on GITHUBHey!
I have Matlab codes available on GitHub, can someone help me out like how i can generate Simulink model from that code?
During the create new simulink project, we see an option wherein you can link with Github.
Please help me out for thisSrividhya Sekar Chttps://it.mathworks.com/matlabcentral/profile/authors/13207233tag:it.mathworks.com,2005:Question/8602402021-06-19T10:09:22Z2021-06-19T13:55:05ZI want to learn Matlab coding , I try a lot but very weak .How to improve my Matlab coding and simulink ?Please suggest me any book or tutorial which is good comphehensive about matlab ,special my programing is very weak any body help me ,Thanksnasir uddinhttps://it.mathworks.com/matlabcentral/profile/authors/15442734tag:it.mathworks.com,2005:Question/8603152021-06-19T13:49:45Z2021-06-19T13:52:44ZData transfer between normal pc and MATLAB system through ethernetCan we transfer data from a system with which acts as a client with no MATLAB to a system with MATLAB through tcp ip program?
If so, can you please provide the link of video for this or a small example.prajwal prakashhttps://it.mathworks.com/matlabcentral/profile/authors/5906188tag:it.mathworks.com,2005:Question/8603102021-06-19T13:49:18Z2021-06-19T13:49:18ZError using plot Vectors must be the same length.Hello,
I am trying to plot Radius verses temperature in my code. Radius is matrix (2030x1354 double) and I just want to plot the radius where M_CP = 2 therefore I did indexing and result is a column vector 668557x1. I've searched that error is because of the different dimensions of x and y but I am unable to resolve this issue. Kindly suggest me what should I do to plot it correctly. Thank you.
M_CP = double(Data_CP); % 2030 x 1354 double (it has values 1, 2, 3 and 4)
M_CT = double(Data_CT); % 2030 x 1354 double
M_CRAD=double(Data_CRAD);
Radius = (M_CRAD).* 0.01; % 2030x1354 double
cldTT = (M_CT -(-15000)).* 0.01; % Converting from Kelvin to C
cldTT1 = cldTT- 273.15; % 2030x1354 double
index_liq = M_CP == 2; %index to find where M_CP ==2
M_RAD_LIQ = Radius(index_liq); % 668557x1 double
plot(M_RAD_LIQ,cldTT1)
Error using plot
Vectors must be the same length.IMChttps://it.mathworks.com/matlabcentral/profile/authors/16183559tag:it.mathworks.com,2005:Question/8597502021-06-18T15:47:49Z2021-06-19T13:43:29ZHow to get row and column from a vector sizeHi matlab Community
i am back again with anouther question
i have a vector with variable length like this :
Vector = [10 20 30 40 50 60 70 80 9 100]
> numel(Vector) =
10
or
Vector = [ 1 2 3 4 5 ]
> numel(Vector) =
5
i want to reshape the vector to a matrix with the 2 largest row and coluumn.
but i can't find out how to go from vector size to matrix row and column
thanks in advanceHoussamhttps://it.mathworks.com/matlabcentral/profile/authors/7798229tag:it.mathworks.com,2005:Question/8603052021-06-19T13:40:13Z2021-06-19T13:40:13ZProblem with simulink 3Dof Hi,
I am having problem simulating a pretty simple balistic trajectory with the 3Dof block. I have a thrust 600N that a certain point becomes zero. When I open the scope connected to to X,Z coordinates it gives me an exponential growing for all the time, with a simulation time of 1000s enough to see the overall trajectory. If I put 3DoF Animation, the animation is correct(showing the ballistic trajectory as it should be) so why the scope show this wrnog data on X,Z ? And how I solve it Francesco Renzullihttps://it.mathworks.com/matlabcentral/profile/authors/19781863tag:it.mathworks.com,2005:Question/8588902021-06-17T15:38:03Z2021-06-19T13:34:31ZHow to integrate one variable in a multivariate formulation+ nonlinear curvefittingHello everyone,
I am facing a probelm with integration, I want to integrate a multiplication of two terms below is the codes:
function y = MH(para,x)
A = para(1);
mu = para(2);
Ms = para(3);
sigma = para(4);
C = para(5);
kb=1.38065e-23;
T=295;
lognormal =@(d) exp(-(log(d/mu).^2/(2*sigma^2)))./(d*sigma*sqrt((2*pi)));
langevin =@(d,x) coth(((d.^3).*pi/6*Ms*x)/(kb*T))-(kb*T)./(pi/6*Ms*x.*d.^3);
integrand = @(d) ((pi/6)*d.^3).*langevin(d,x).*lognormal(d);
y = A*integral(integrand,0,inf)+C*x;
end
Actually, I am trying to fit a M(H) curve, the formulation is:
where
,
The unknown parameters are A, Ms, Sigma, Mu and C,.
The two variables are H and d, H is the xdata with a dimension of (61×1) and in this code it is replaced as x, d is the variable that should be integrated and has a limit of integration of (0,inf).
The problem is, the part 'intergrand' isn't integrated at all and it isn't fitted, only the part C*x is fitted, the returned parameter Ms, Sigma and Mu doesn't change from the estimated parameter at beginning, only A and C changed, the result is as below:
Red points are the data that need to be fitted and blue line is the fitting curve.
May I ask what's the reason for that? Thanks for any help in advance!Zhaohttps://it.mathworks.com/matlabcentral/profile/authors/22844474tag:it.mathworks.com,2005:Question/8602052021-06-19T09:09:04Z2021-06-19T13:29:31Zis there any function for CalinskiHarabasz just like silhouette(X,cidx) in matlabAs silhouette(X,cidx) function plot graph of score for each data point. I want to know that is there similar function
for CalinskiHarabasz in matlab.Kshitij Tripathihttps://it.mathworks.com/matlabcentral/profile/authors/6562012tag:it.mathworks.com,2005:Question/8603002021-06-19T13:27:45Z2021-06-19T13:27:45ZResolving missing coverage using simulink design verifier and not by using simulink testI have a complex stateflow subsystem which has given me less coverage while using simulink coverage and simulink design verifer license. Is there any formal method to resolve the missing coverage without using simulink Test license nor do I use reactis license
My approaches so far
I have even tried generating multiple .cvt files (coverage files) but thats not helping me to maximise the coverage.
Does entering range of min and max values of inputs help to maximise the coverage.Rahulhttps://it.mathworks.com/matlabcentral/profile/authors/4472306tag:it.mathworks.com,2005:Question/8591952021-06-18T01:45:20Z2021-06-19T13:25:43Zthree-axle vehicle body modelHi all
I want to know how Vehicle Body 3DOF Three Axles block calculates Fzf, Fzm, Fzr, the normal force applied to front middle and rear wheels, along vehicle-fixed z-axis
Vehicle Body 3DOF Three Axles block use this equations to calculate Fzf, Fzr
please help!Chen Jiayihttps://it.mathworks.com/matlabcentral/profile/authors/20000735tag:it.mathworks.com,2005:Question/8584602021-06-17T08:37:49Z2021-06-19T13:25:35ZMaximum recursion limit of 500 reached.While using code
clc;
clear all;
A=35:1:45;
x=[A];
y=[0:.1:1];
z = randi([0 1],11,11);
pcolor(x,y,z)
shading interp
colormap
i am getting the following error
Maximum recursion limit of 500 reached.
Error in axescheck (line 34)
inds = find(cellfun(@(x) (isStringScalar(x) || ischar(x)) && strcmpi('parent', x), args));
Caused by:
Maximum recursion limit of 500 reached.
Please help how to solve above error.baljit singhhttps://it.mathworks.com/matlabcentral/profile/authors/9214825tag:it.mathworks.com,2005:Question/7494722021-02-18T17:31:35Z2021-06-19T13:22:58Zhow do implement this function in matlab for calculating fourier cofficient ?Hello everyone ✋🌷
How can i implement this function in matlab ?
I want to calculate fourier cofficient (a0,bn,an) for this function in matlab acording to their formula.
I used symsum for implementation this function but matlab answer symsum again!!!
Help me please🙏🌷amir eshghihttps://it.mathworks.com/matlabcentral/profile/authors/21568569tag:it.mathworks.com,2005:Question/5155852020-04-05T19:03:41Z2021-06-19T13:22:12ZHow can I extract non-consecutive indices from a vector?In 5.2 Extracting Multiple Elements, Further practice "Indices can be non-consecutive numbers. Try extracting the first, third, and sixth elements of density." How?Ray Smithhttps://it.mathworks.com/matlabcentral/profile/authors/18052480tag:it.mathworks.com,2005:Question/932752009-06-27T01:12:00Z2021-06-19T13:20:40ZHow can I randomly combine the elements of two arrays in MATLAB 7.5 (R2007b)?I have two one dimensional arrays. I would like to combine them to create a third array with the elements in a random order.
MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813tag:it.mathworks.com,2005:Question/8582952021-06-17T02:04:20Z2021-06-19T13:18:54Zproblem in the effect of aerodynamicsI want to ignore the effect of aerodynamics when I use block vehicle body 3DOF
what should I set aerodynamic parameters in vehicle body 3DOF block ?Chen Jiayihttps://it.mathworks.com/matlabcentral/profile/authors/20000735tag:it.mathworks.com,2005:Question/8587202021-06-17T13:04:18Z2021-06-19T13:11:11Zsecond order differential systems of a non linear ODEConsidering theth differential system equations to be solved are:
f''(t) = 3*f(t)*g(t) + 5 g''(t) = 4*g(t)*f(t) + 7 with initial conditions: f(0) = 1.5, g'(0) = 0 and boundary constraints tf = 1: g(1) = 3, f'(1) =q* f(1)
With q is natural number
how we can plot the solution satysfying the boundary conditionsLewis Ferhttps://it.mathworks.com/matlabcentral/profile/authors/22804303tag:it.mathworks.com,2005:Question/5479412020-06-14T10:05:15Z2021-06-19T13:09:07ZHow to create fft Magnitude and Phase using stem Matlab?With the function
cos(w0t)
, first create your own time domain data and second, conduct
the FT (Fourier transform). When you solve the problem, use the MATLAB codes with
two “for ~ end” loops without using already built-in functions except for the fundamental
ones such as “linspace” and “cos”. Then draw the result of the FT in frequency domain in
terms of “Magnitude vs. freq.” and “Phase vs. freq.” by using “stem” instead of “plot”.
Here, let’s set w0=2pi/T and T = 1(sec).sejong sinhttps://it.mathworks.com/matlabcentral/profile/authors/17948162tag:it.mathworks.com,2005:Question/8601802021-06-19T08:19:12Z2021-06-19T13:03:37Zintegral of a matrixI want to take the integral of an exponetial of a matrix but I got this error and dont know how fix it:
'Unable to perform assignment because the indices on the left side are not compatible with the size of
the right side.
Error in Untitled7 (line 12)
ggg(ss)=integral(fun,0,T,'ArrayValued',true);'
thanks in advance
clc
clear
close all
M=ones(3,3);
Dmat=[1;2;3];
fun=@(t)expm(-M.*t)*Dmat;
T=1e-2;
g=integral(fun,0,T,'ArrayValued',true);raha ahmadihttps://it.mathworks.com/matlabcentral/profile/authors/15825722tag:it.mathworks.com,2005:Question/8323832021-05-17T15:19:43Z2021-06-19T13:02:24ZBessel function. Determining the roots.How do I solve the following problem? Determine the first six roots Bi Jn (B) = 0 for n = 1,2,3 and 4FREDERICO CARVALHOhttps://it.mathworks.com/matlabcentral/profile/authors/20138082tag:it.mathworks.com,2005:Question/8602202021-06-19T09:42:54Z2021-06-19T13:02:07ZRunning all Nastran input .bdf files contained in a folder using MatlabHello everyone,
I am trying to run a number of nastran input.bdf files contained in a folder using "system "command in matlab
System command works well when i secify onle one file named"1.bdf" like:
system('D:\MSC.Software\MSC_Nastran\20180\bin\nastranw.exe 1.bdf')
But,I have three bdf files in folder, I am trying to run using for loop
I have tried:
..................................................................................
files = dir('*.bdf');
for i = 1 : length(files)
filename = files(K).name;
system('D:\MSC.Software\MSC_Nastran\20180\bin\nastranw.exe filename')
end
.......................................................................................
But it does not start nastran ,rather gives output such as
ans=0
ans=0
ans=0Zia Rehmanhttps://it.mathworks.com/matlabcentral/profile/authors/17607893tag:it.mathworks.com,2005:Question/8590702021-06-17T19:25:16Z2021-06-19T12:59:16ZLeft ventricular segmentation in Cardiac Magnetic Resonance ImagingI want to segment the left ventricle on MR images. I've already tried using active contours but the results I got didn't work for what I wanted.
What I would like to know is if you could recommend any automatic segmentation method applicable to these types of images to isolate the left ventricle from the rest of the image and then isolate the trabeculae, if any.
Thanks.Ana Ferreirahttps://it.mathworks.com/matlabcentral/profile/authors/18118553tag:it.mathworks.com,2005:Question/8602852021-06-19T12:52:11Z2021-06-19T12:52:11ZPhase-based connectivity preparation scriptDear Community,
I have a sample with EC rsEEG data, everything is already preprocessed etc. through a matlab eeglab script.
Now for the last step i want to do a phase-based connectivity analyses from Mike Cohen's example script.
I want to compare 8 frontal electrodes (I did neuromodulation in that region) from pre to post. So first calculate the phase-based connectivity pre and then post and compare these. (I hope I choose the right analysi).
But If i open up my data (throughout eeglab and load it into matlab) I get a 1x43 struct (43 participants) and with mike cohen's data it is a 1x1 struct, so he can load all the participants at once for his script, how do I change that? So I have one setname to put in the script instead of all the participants separetly.
I made a study but if I load the study into the script that does not work..
I hope this makes sense and that there is somebody that can help me. I am in the last phase of my PhD and have a hard time completing this last step.
All the best,
Carmen SergiouCarmen Sergiouhttps://it.mathworks.com/matlabcentral/profile/authors/13096487tag:it.mathworks.com,2005:Question/5787152020-08-12T16:45:32Z2021-06-19T12:39:42Zhow to compute the complex Fourier series expansion of half-wave rectified signal. and plot its phase and amplitude spectrum?My Question in the title, i am new to matlab and i need help with this please
WJhttps://it.mathworks.com/matlabcentral/profile/authors/19152765tag:it.mathworks.com,2005:Question/8602702021-06-19T12:33:40Z2021-06-19T12:33:40ZSPEED CONTROL OF DC MOTOR USING PIDHi,I'm trying to simulate the Speed control of a DC motor using a Pid controller.The transfer function of this motor is: K/(Ls+R)(Js+b)+K^2while the input is:v(s)+Td*(Ls+R/K), v(s) is a unit step and i have no difficulty to simulate the step responce, but when i put Td different from 0, my simulation doesn't work properly.What is the problem of this code?
Giuseppe D'Auriahttps://it.mathworks.com/matlabcentral/profile/authors/22660504tag:it.mathworks.com,2005:Question/8602652021-06-19T12:29:07Z2021-06-19T12:29:07ZLSTM get percentage of each classHi! Is there a way to get a percantage of each class from a classifier?
For example: I have 5 classes: Sit, Eat, Drink, Run and Sleep
I am giving some data to the trained classifier and it predicts one of the classes.
Can it give me something like: Sit 90%, Eat 2% Drink 5% Run 2% and Sleep 1%?
Like for each line of input to give me all the existing classes and the probability.
The reason why i want this is that i am trying to classify some activities that sometimes may happen in the same time. And i would like to see which have some kind of big percentage, let's say over 50%, then this 2 activities are happening.
Is there a way?Laura Gabrielahttps://it.mathworks.com/matlabcentral/profile/authors/16905385tag:it.mathworks.com,2005:Question/4106762018-07-17T08:38:14Z2021-06-19T12:15:24ZCurve fitting with an integral involvedI have a 2 parameter model that includes an integral function and I´m quite lost how to solve this.
My data consists of a set of given molecule sizes, r_m, and a calculated response, K.
I want to fit this K with a theoretical model, where each K_i comes from integrating a particle size distribiution function, f(r), for instance a Gaussian distribution. The equations then look like this:
<</matlabcentral/answers/uploaded_files/125449/equations_model_stck.PNG>>
as you can see the integral function has the parameteres that I want to fit, but also the lower limit of the integral in the numerator involves a variable, r_m. I´m not sure if I can implement this situation to one of Matlab´s built-in fitting procedures, or do I have to code my own fitting algorithm? Here´s something I tried but I know I´m just playing Frankenstein here:
% Data = ...
[0.5 1
1.1 0.83
1.6 0.74
2.2 0.55
2.5 0.28
3.5 0];
r = Data(:,1);
K_exp = Data(:,2);
F = @(x,xdata) quad( (exp(-1/2.*((xdata - x(1))/x(2)).^2).*(1 - (xdata(1)/xdata).^2)),xdata(1),120)./quad(exp(-1/2.*((xdata - x(1))/x(2)).^2,0,120) ; ;
x0 = [6 0.5] ;
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,r,K_exp)
Any help on how to approach this problem is greatly appreciated!
Eugenio Gilhttps://it.mathworks.com/matlabcentral/profile/authors/13162922