Tag Archives: matlab
My question is what is the value i am getting as the output of my code.
syms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
solve(eqn == 0,x)
the results are given assyms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
solve(eqn == 0,x)
the results are given as syms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
solve(eqn == 0,x)
the results are given as linear equation MATLAB Answers — New Questions
TI C2000 f28388d SPI Tx and SPI Rx with multiple chip select GPIOs
My application requires connecting SPI to multiple devices using multiple chip select GPIOs. I tried to make the "Chip select pin" as a variable but it didn’t work. How can I implement this use case with multiple chip selects?My application requires connecting SPI to multiple devices using multiple chip select GPIOs. I tried to make the "Chip select pin" as a variable but it didn’t work. How can I implement this use case with multiple chip selects? My application requires connecting SPI to multiple devices using multiple chip select GPIOs. I tried to make the "Chip select pin" as a variable but it didn’t work. How can I implement this use case with multiple chip selects? spi, tms320f28388d MATLAB Answers — New Questions
Invalid setting in ‘Model’ for parameter ‘Gain’.
I am trying to tune a PID controller for controlling a plant model buit in Simulink. My aim is to obtain the gains of the PID controller using an optimization technique whose code is written in a script file. So, the objective function is calculated by obtaining the loged values from the simulink model. While I run my code, it always shows the error: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’, where the simulink file’s name is Model. Since I am tuning the gains using optimization, the are changing in each iteration. Kp, Ki, and Kd are the gains. The error is: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’.
function objective_func = F3(x)
Kp=x(1)
Ki=x(2)
Kd=x(3)
mdl = "Model";
open_system(mdl)
in = Simulink.SimulationInput(mdl)
out = sim(in)
simout = out.J(3001) %objective function value
objective_func=simout;
endI am trying to tune a PID controller for controlling a plant model buit in Simulink. My aim is to obtain the gains of the PID controller using an optimization technique whose code is written in a script file. So, the objective function is calculated by obtaining the loged values from the simulink model. While I run my code, it always shows the error: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’, where the simulink file’s name is Model. Since I am tuning the gains using optimization, the are changing in each iteration. Kp, Ki, and Kd are the gains. The error is: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’.
function objective_func = F3(x)
Kp=x(1)
Ki=x(2)
Kd=x(3)
mdl = "Model";
open_system(mdl)
in = Simulink.SimulationInput(mdl)
out = sim(in)
simout = out.J(3001) %objective function value
objective_func=simout;
end I am trying to tune a PID controller for controlling a plant model buit in Simulink. My aim is to obtain the gains of the PID controller using an optimization technique whose code is written in a script file. So, the objective function is calculated by obtaining the loged values from the simulink model. While I run my code, it always shows the error: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’, where the simulink file’s name is Model. Since I am tuning the gains using optimization, the are changing in each iteration. Kp, Ki, and Kd are the gains. The error is: Invalid setting in ‘Model/PID/Gain’ for parameter ‘Gain’.
function objective_func = F3(x)
Kp=x(1)
Ki=x(2)
Kd=x(3)
mdl = "Model";
open_system(mdl)
in = Simulink.SimulationInput(mdl)
out = sim(in)
simout = out.J(3001) %objective function value
objective_func=simout;
end simulink, gain block, optimization MATLAB Answers — New Questions
Interpolation of two-dimensional within a given space window
Dear all
I am attaching a dataset, called "Points.txt", where the first and second columns represent the spatial coordinates along the x- and y-th directions, respectively, and the third column the value of a variable at each listed pair of points (x,y). I was wondering which could be a good way to increase the number of points mainly inside the hexagonal shape within the current listed points are restricted to:
I have tried the following:
pgon=nsidedpoly(6,’Center’,[0 0],’SideLength’,1);
%% Let’s rearrange the data associated to the interlayer isotropic exchange, Jinter
% Let’s load the preliminar data
Jinter=cell2mat(struct2cell(load(strcat(pwd,’Preliminar-DataJinter.mat’))));
% Let’s construct the unit vectors of the in-plane unit cell
x=unique(Jinter(:,1));
y=unique(Jinter(:,2));
a1_points=[max(x) 0];
a2_points=[-0.5 max(y)];
a1_modulus=sqrt(dot(a1_points,a1_points));
a2_modulus=sqrt(dot(a2_points,a2_points));
a1=a1_points./a1_modulus;
a2=a2_points./a2_modulus;
% Let’s construct the supercell for Jinter
diff_y=max(y)-min(y);
counter=0;
for dy=[-1 0 1]
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)++dy*[0 1]*diff_y)~=any(Jinter(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+dy*[0 1]*diff_y;
Jinter_extended(counter,3)=Jinter(i,3);
end
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
clear a1 a2 a1_modulus a2_modulus a1_points a2_points Jinter diff_y x y dy
% Let’s plot it
u17=figure(17)
scatter(Jinter_extended(:,1),Jinter_extended(:,2),[],Jinter_extended(:,3),’o’,’filled’);
colormap(gca,bluewhitered(256));
clim([min(Jinter_extended(:,3)) max(Jinter_extended(:,3))]);
clr17=colorbar;
box on;
pbaspect([1 6/4 1]);
clear u17 clr17
% Now, let’s interpolate data
x_extended=linspace(min(Jinter_extended(:,1)),max(Jinter_extended(:,1)));
y_extended=linspace(min(Jinter_extended(:,2)),max(Jinter_extended(:,2)));
Jinter_interpolated=RegularizeData3D(Jinter_extended(:,1),Jinter_extended(:,2),Jinter_extended(:,3),x_extended,y_extended,’interp’,’bicubic’,’smoothness’,1e-4);
x_interpolation=linspace(-1,1,201);
y_interpolation=linspace(-sqrt(3)/2,sqrt(3)/2,201);
[X,Y]=meshgrid(x_interpolation,y_interpolation);
interpolated_Jinter=interp2(x_extended,y_extended,Jinter_interpolated,X,Y,’cubic’);
clear X Y Jinter_interpolated x_extended y_extended Jinter_extended
% Let’s plot it
u18=figure(18)
uimagesc(x_interpolation,y_interpolation,interpolated_Jinter);
colormap(gca,bluewhitered(256));
% hold on
axis xy;
% plot(pgon);
clim([min(min(interpolated_Jinter)) max(max(interpolated_Jinter))]);
clr18=colorbar;
box on;
pbaspect([1 sqrt(3)/2 1]);
clear u18 clr18
% Now, let’s rearrange and save the data
x_intermediate=linspace(-100,100,201);
y_intermediate=linspace(-100,100,201);
counter=0;
for i=1:length(x_interpolation)
for j=1:length(y_interpolation)
counter=counter+1;
Jinter_save(counter,1)=x_intermediate(i);
Jinter_save(counter,2)=y_intermediate(j);
Jinter_save(counter,3)=interpolated_Jinter(i,j);
end
end
writematrix(Jinter_save,strcat(pwd,’Interpolated-DataInterpolated_J_Inter.txt’),’Delimiter’,’space’);
clear interpolated_Jinter Jinter_save x_interpolation y_interpolation counter i j x_intermediate y_intermediate
where the "Jinter.mat" is exactly the same dataset as in "Points.txt". The problem with this is that, for example, if I take a look at the generated "Interpolated_J_Inter.txt", the value for (0,0) differs notably.
Any ideas?Dear all
I am attaching a dataset, called "Points.txt", where the first and second columns represent the spatial coordinates along the x- and y-th directions, respectively, and the third column the value of a variable at each listed pair of points (x,y). I was wondering which could be a good way to increase the number of points mainly inside the hexagonal shape within the current listed points are restricted to:
I have tried the following:
pgon=nsidedpoly(6,’Center’,[0 0],’SideLength’,1);
%% Let’s rearrange the data associated to the interlayer isotropic exchange, Jinter
% Let’s load the preliminar data
Jinter=cell2mat(struct2cell(load(strcat(pwd,’Preliminar-DataJinter.mat’))));
% Let’s construct the unit vectors of the in-plane unit cell
x=unique(Jinter(:,1));
y=unique(Jinter(:,2));
a1_points=[max(x) 0];
a2_points=[-0.5 max(y)];
a1_modulus=sqrt(dot(a1_points,a1_points));
a2_modulus=sqrt(dot(a2_points,a2_points));
a1=a1_points./a1_modulus;
a2=a2_points./a2_modulus;
% Let’s construct the supercell for Jinter
diff_y=max(y)-min(y);
counter=0;
for dy=[-1 0 1]
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)++dy*[0 1]*diff_y)~=any(Jinter(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+dy*[0 1]*diff_y;
Jinter_extended(counter,3)=Jinter(i,3);
end
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
clear a1 a2 a1_modulus a2_modulus a1_points a2_points Jinter diff_y x y dy
% Let’s plot it
u17=figure(17)
scatter(Jinter_extended(:,1),Jinter_extended(:,2),[],Jinter_extended(:,3),’o’,’filled’);
colormap(gca,bluewhitered(256));
clim([min(Jinter_extended(:,3)) max(Jinter_extended(:,3))]);
clr17=colorbar;
box on;
pbaspect([1 6/4 1]);
clear u17 clr17
% Now, let’s interpolate data
x_extended=linspace(min(Jinter_extended(:,1)),max(Jinter_extended(:,1)));
y_extended=linspace(min(Jinter_extended(:,2)),max(Jinter_extended(:,2)));
Jinter_interpolated=RegularizeData3D(Jinter_extended(:,1),Jinter_extended(:,2),Jinter_extended(:,3),x_extended,y_extended,’interp’,’bicubic’,’smoothness’,1e-4);
x_interpolation=linspace(-1,1,201);
y_interpolation=linspace(-sqrt(3)/2,sqrt(3)/2,201);
[X,Y]=meshgrid(x_interpolation,y_interpolation);
interpolated_Jinter=interp2(x_extended,y_extended,Jinter_interpolated,X,Y,’cubic’);
clear X Y Jinter_interpolated x_extended y_extended Jinter_extended
% Let’s plot it
u18=figure(18)
uimagesc(x_interpolation,y_interpolation,interpolated_Jinter);
colormap(gca,bluewhitered(256));
% hold on
axis xy;
% plot(pgon);
clim([min(min(interpolated_Jinter)) max(max(interpolated_Jinter))]);
clr18=colorbar;
box on;
pbaspect([1 sqrt(3)/2 1]);
clear u18 clr18
% Now, let’s rearrange and save the data
x_intermediate=linspace(-100,100,201);
y_intermediate=linspace(-100,100,201);
counter=0;
for i=1:length(x_interpolation)
for j=1:length(y_interpolation)
counter=counter+1;
Jinter_save(counter,1)=x_intermediate(i);
Jinter_save(counter,2)=y_intermediate(j);
Jinter_save(counter,3)=interpolated_Jinter(i,j);
end
end
writematrix(Jinter_save,strcat(pwd,’Interpolated-DataInterpolated_J_Inter.txt’),’Delimiter’,’space’);
clear interpolated_Jinter Jinter_save x_interpolation y_interpolation counter i j x_intermediate y_intermediate
where the "Jinter.mat" is exactly the same dataset as in "Points.txt". The problem with this is that, for example, if I take a look at the generated "Interpolated_J_Inter.txt", the value for (0,0) differs notably.
Any ideas? Dear all
I am attaching a dataset, called "Points.txt", where the first and second columns represent the spatial coordinates along the x- and y-th directions, respectively, and the third column the value of a variable at each listed pair of points (x,y). I was wondering which could be a good way to increase the number of points mainly inside the hexagonal shape within the current listed points are restricted to:
I have tried the following:
pgon=nsidedpoly(6,’Center’,[0 0],’SideLength’,1);
%% Let’s rearrange the data associated to the interlayer isotropic exchange, Jinter
% Let’s load the preliminar data
Jinter=cell2mat(struct2cell(load(strcat(pwd,’Preliminar-DataJinter.mat’))));
% Let’s construct the unit vectors of the in-plane unit cell
x=unique(Jinter(:,1));
y=unique(Jinter(:,2));
a1_points=[max(x) 0];
a2_points=[-0.5 max(y)];
a1_modulus=sqrt(dot(a1_points,a1_points));
a2_modulus=sqrt(dot(a2_points,a2_points));
a1=a1_points./a1_modulus;
a2=a2_points./a2_modulus;
% Let’s construct the supercell for Jinter
diff_y=max(y)-min(y);
counter=0;
for dy=[-1 0 1]
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)++dy*[0 1]*diff_y)~=any(Jinter(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+dy*[0 1]*diff_y;
Jinter_extended(counter,3)=Jinter(i,3);
end
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[a1(1)+abs(a2(1)) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
counter=length(Jinter_extended(:,1));
for i=1:length(Jinter(:,1))
if (Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))])~=any(Jinter_extended(:,1:2))
counter=counter+1;
Jinter_extended(counter,1:2)=Jinter(i,1:2)+[-(a1(1)+abs(a2(1))) -abs(a2(2))];
Jinter_extended(counter,3)=Jinter(i,3);
end
end
clear a1 a2 a1_modulus a2_modulus a1_points a2_points Jinter diff_y x y dy
% Let’s plot it
u17=figure(17)
scatter(Jinter_extended(:,1),Jinter_extended(:,2),[],Jinter_extended(:,3),’o’,’filled’);
colormap(gca,bluewhitered(256));
clim([min(Jinter_extended(:,3)) max(Jinter_extended(:,3))]);
clr17=colorbar;
box on;
pbaspect([1 6/4 1]);
clear u17 clr17
% Now, let’s interpolate data
x_extended=linspace(min(Jinter_extended(:,1)),max(Jinter_extended(:,1)));
y_extended=linspace(min(Jinter_extended(:,2)),max(Jinter_extended(:,2)));
Jinter_interpolated=RegularizeData3D(Jinter_extended(:,1),Jinter_extended(:,2),Jinter_extended(:,3),x_extended,y_extended,’interp’,’bicubic’,’smoothness’,1e-4);
x_interpolation=linspace(-1,1,201);
y_interpolation=linspace(-sqrt(3)/2,sqrt(3)/2,201);
[X,Y]=meshgrid(x_interpolation,y_interpolation);
interpolated_Jinter=interp2(x_extended,y_extended,Jinter_interpolated,X,Y,’cubic’);
clear X Y Jinter_interpolated x_extended y_extended Jinter_extended
% Let’s plot it
u18=figure(18)
uimagesc(x_interpolation,y_interpolation,interpolated_Jinter);
colormap(gca,bluewhitered(256));
% hold on
axis xy;
% plot(pgon);
clim([min(min(interpolated_Jinter)) max(max(interpolated_Jinter))]);
clr18=colorbar;
box on;
pbaspect([1 sqrt(3)/2 1]);
clear u18 clr18
% Now, let’s rearrange and save the data
x_intermediate=linspace(-100,100,201);
y_intermediate=linspace(-100,100,201);
counter=0;
for i=1:length(x_interpolation)
for j=1:length(y_interpolation)
counter=counter+1;
Jinter_save(counter,1)=x_intermediate(i);
Jinter_save(counter,2)=y_intermediate(j);
Jinter_save(counter,3)=interpolated_Jinter(i,j);
end
end
writematrix(Jinter_save,strcat(pwd,’Interpolated-DataInterpolated_J_Inter.txt’),’Delimiter’,’space’);
clear interpolated_Jinter Jinter_save x_interpolation y_interpolation counter i j x_intermediate y_intermediate
where the "Jinter.mat" is exactly the same dataset as in "Points.txt". The problem with this is that, for example, if I take a look at the generated "Interpolated_J_Inter.txt", the value for (0,0) differs notably.
Any ideas? interpolate two-dimensional data MATLAB Answers — New Questions
Simulink generated code optimization – CPU Load
Hi all,
I’m successfully generating code from the Simulink model. This code substitute manual one with the same function. Code is the integrated with the rest of the manual code, flashed to the HW and running. This substituting of the manual code part with the generated one increses the CPU Load. When I’m checking the Code generation setting, basic targets are RAM minimazing or Execution speed mazimazing. Non of these will directly reduce the CPU Load I suppose.
So I’d like to ask you, do you know what Advanced or Detailed Code generation Optimization setting can reduce the CPU Load? I’m attaching screenshots of the current setting.
And possibly follow up question – is there any metric which can estimate affect on the CPU Load without need of flashing the integrated code to the HW?
Thank you for your help in advance, have a nice day!
OldrichHi all,
I’m successfully generating code from the Simulink model. This code substitute manual one with the same function. Code is the integrated with the rest of the manual code, flashed to the HW and running. This substituting of the manual code part with the generated one increses the CPU Load. When I’m checking the Code generation setting, basic targets are RAM minimazing or Execution speed mazimazing. Non of these will directly reduce the CPU Load I suppose.
So I’d like to ask you, do you know what Advanced or Detailed Code generation Optimization setting can reduce the CPU Load? I’m attaching screenshots of the current setting.
And possibly follow up question – is there any metric which can estimate affect on the CPU Load without need of flashing the integrated code to the HW?
Thank you for your help in advance, have a nice day!
Oldrich Hi all,
I’m successfully generating code from the Simulink model. This code substitute manual one with the same function. Code is the integrated with the rest of the manual code, flashed to the HW and running. This substituting of the manual code part with the generated one increses the CPU Load. When I’m checking the Code generation setting, basic targets are RAM minimazing or Execution speed mazimazing. Non of these will directly reduce the CPU Load I suppose.
So I’d like to ask you, do you know what Advanced or Detailed Code generation Optimization setting can reduce the CPU Load? I’m attaching screenshots of the current setting.
And possibly follow up question – is there any metric which can estimate affect on the CPU Load without need of flashing the integrated code to the HW?
Thank you for your help in advance, have a nice day!
Oldrich embedded coder MATLAB Answers — New Questions
Plotting a system of fractional order differential equations
Hi. I have been trying to plot fractional order differential equations with MATLAB. I have tried to use this technique called "Predictor-Corrector Method" and got a code listing using AI. The code seems to be giving the plots, though they do not match with the expected results. I will attach the code listing below. But my question is how to actually plot such systems? Is there a standard method in-built, or a widely accepted add-on/package? Thanks. “`% Parameters
alpha = 0.9;
LAMBDA = 3;
mu = 0.4;
beta = 0.004;
gamma = 0.0005;
m = 0.03;
n = 0.006;
delta = 0.02;
rho = 0.003;
h = 0.1; % Time step
T = 300; % Total time
% Time steps
time = 0:h:T;
time_steps = length(time);
% Initial conditions
s = zeros(1, time_steps);
i = zeros(1, time_steps);
r = zeros(1, time_steps);
s(1) = 85;
i(1) = 3;
r(1) = 0;
% Predictor-Corrector Method
for k = 1:(time_steps – 1)
% Predictor step (Adams-Bashforth)
if k == 1
ds_pred = h * (LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k)));
di_pred = h * ((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k));
dr_pred = h * ((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k));
else
ds_pred = h / 2 * ((LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k))) + …
(LAMBDA – mu * s(k-1) – (beta * s(k-1) * i(k-1)) / (1 + gamma * i(k-1))));
di_pred = h / 2 * (((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k)) + …
((beta * s(k-1) * i(k-1)) / (1 + gamma * i(k-1)) – (m * i(k-1)) / (1 + n * i(k-1)) – (mu + delta + rho) * i(k-1)));
dr_pred = h / 2 * (((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k)) + …
((m * i(k-1)) / (1 + n * i(k-1)) + delta * i(k-1) – mu * r(k-1)));
end
% Update predicted values
s(k + 1) = s(k) + ds_pred;
i(k + 1) = i(k) + di_pred;
r(k + 1) = r(k) + dr_pred;
% Corrector step (Adams-Moulton)
ds_corr = h / 2 * ((LAMBDA – mu * s(k + 1) – (beta * s(k + 1) * i(k + 1)) / (1 + gamma * i(k + 1))) + …
(LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k))));
di_corr = h / 2 * (((beta * s(k + 1) * i(k + 1)) / (1 + gamma * i(k + 1)) – (m * i(k + 1)) / (1 + n * i(k + 1)) – (mu + delta + rho) * i(k + 1)) + …
((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k)));
dr_corr = h / 2 * (((m * i(k + 1)) / (1 + n * i(k + 1)) + delta * i(k + 1) – mu * r(k + 1)) + …
((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k)));
% Update corrected values
s(k + 1) = s(k) + ds_corr;
i(k + 1) = i(k) + di_corr;
r(k + 1) = r(k) + dr_corr;
end
% Plot the results
figure;
plot(time, s, ‘-o’, ‘DisplayName’, ‘s(t)’);
hold on;
plot(time, i, ‘-s’, ‘DisplayName’, ‘i(t)’);
plot(time, r, ‘-d’, ‘DisplayName’, ‘r(t)’);
xlabel(‘Time’);
ylabel(‘Population’);
title(‘Solution of the System of Fractional Differential Equations’);
legend;
grid on;
% Set plot range
xlim([0 30]);
ylim([0 100]);“`
<</matlabcentral/answers/uploaded_files/1745286/fo_M.png>>Hi. I have been trying to plot fractional order differential equations with MATLAB. I have tried to use this technique called "Predictor-Corrector Method" and got a code listing using AI. The code seems to be giving the plots, though they do not match with the expected results. I will attach the code listing below. But my question is how to actually plot such systems? Is there a standard method in-built, or a widely accepted add-on/package? Thanks. “`% Parameters
alpha = 0.9;
LAMBDA = 3;
mu = 0.4;
beta = 0.004;
gamma = 0.0005;
m = 0.03;
n = 0.006;
delta = 0.02;
rho = 0.003;
h = 0.1; % Time step
T = 300; % Total time
% Time steps
time = 0:h:T;
time_steps = length(time);
% Initial conditions
s = zeros(1, time_steps);
i = zeros(1, time_steps);
r = zeros(1, time_steps);
s(1) = 85;
i(1) = 3;
r(1) = 0;
% Predictor-Corrector Method
for k = 1:(time_steps – 1)
% Predictor step (Adams-Bashforth)
if k == 1
ds_pred = h * (LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k)));
di_pred = h * ((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k));
dr_pred = h * ((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k));
else
ds_pred = h / 2 * ((LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k))) + …
(LAMBDA – mu * s(k-1) – (beta * s(k-1) * i(k-1)) / (1 + gamma * i(k-1))));
di_pred = h / 2 * (((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k)) + …
((beta * s(k-1) * i(k-1)) / (1 + gamma * i(k-1)) – (m * i(k-1)) / (1 + n * i(k-1)) – (mu + delta + rho) * i(k-1)));
dr_pred = h / 2 * (((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k)) + …
((m * i(k-1)) / (1 + n * i(k-1)) + delta * i(k-1) – mu * r(k-1)));
end
% Update predicted values
s(k + 1) = s(k) + ds_pred;
i(k + 1) = i(k) + di_pred;
r(k + 1) = r(k) + dr_pred;
% Corrector step (Adams-Moulton)
ds_corr = h / 2 * ((LAMBDA – mu * s(k + 1) – (beta * s(k + 1) * i(k + 1)) / (1 + gamma * i(k + 1))) + …
(LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k))));
di_corr = h / 2 * (((beta * s(k + 1) * i(k + 1)) / (1 + gamma * i(k + 1)) – (m * i(k + 1)) / (1 + n * i(k + 1)) – (mu + delta + rho) * i(k + 1)) + …
((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k)));
dr_corr = h / 2 * (((m * i(k + 1)) / (1 + n * i(k + 1)) + delta * i(k + 1) – mu * r(k + 1)) + …
((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k)));
% Update corrected values
s(k + 1) = s(k) + ds_corr;
i(k + 1) = i(k) + di_corr;
r(k + 1) = r(k) + dr_corr;
end
% Plot the results
figure;
plot(time, s, ‘-o’, ‘DisplayName’, ‘s(t)’);
hold on;
plot(time, i, ‘-s’, ‘DisplayName’, ‘i(t)’);
plot(time, r, ‘-d’, ‘DisplayName’, ‘r(t)’);
xlabel(‘Time’);
ylabel(‘Population’);
title(‘Solution of the System of Fractional Differential Equations’);
legend;
grid on;
% Set plot range
xlim([0 30]);
ylim([0 100]);“`
<</matlabcentral/answers/uploaded_files/1745286/fo_M.png>> Hi. I have been trying to plot fractional order differential equations with MATLAB. I have tried to use this technique called "Predictor-Corrector Method" and got a code listing using AI. The code seems to be giving the plots, though they do not match with the expected results. I will attach the code listing below. But my question is how to actually plot such systems? Is there a standard method in-built, or a widely accepted add-on/package? Thanks. “`% Parameters
alpha = 0.9;
LAMBDA = 3;
mu = 0.4;
beta = 0.004;
gamma = 0.0005;
m = 0.03;
n = 0.006;
delta = 0.02;
rho = 0.003;
h = 0.1; % Time step
T = 300; % Total time
% Time steps
time = 0:h:T;
time_steps = length(time);
% Initial conditions
s = zeros(1, time_steps);
i = zeros(1, time_steps);
r = zeros(1, time_steps);
s(1) = 85;
i(1) = 3;
r(1) = 0;
% Predictor-Corrector Method
for k = 1:(time_steps – 1)
% Predictor step (Adams-Bashforth)
if k == 1
ds_pred = h * (LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k)));
di_pred = h * ((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k));
dr_pred = h * ((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k));
else
ds_pred = h / 2 * ((LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k))) + …
(LAMBDA – mu * s(k-1) – (beta * s(k-1) * i(k-1)) / (1 + gamma * i(k-1))));
di_pred = h / 2 * (((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k)) + …
((beta * s(k-1) * i(k-1)) / (1 + gamma * i(k-1)) – (m * i(k-1)) / (1 + n * i(k-1)) – (mu + delta + rho) * i(k-1)));
dr_pred = h / 2 * (((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k)) + …
((m * i(k-1)) / (1 + n * i(k-1)) + delta * i(k-1) – mu * r(k-1)));
end
% Update predicted values
s(k + 1) = s(k) + ds_pred;
i(k + 1) = i(k) + di_pred;
r(k + 1) = r(k) + dr_pred;
% Corrector step (Adams-Moulton)
ds_corr = h / 2 * ((LAMBDA – mu * s(k + 1) – (beta * s(k + 1) * i(k + 1)) / (1 + gamma * i(k + 1))) + …
(LAMBDA – mu * s(k) – (beta * s(k) * i(k)) / (1 + gamma * i(k))));
di_corr = h / 2 * (((beta * s(k + 1) * i(k + 1)) / (1 + gamma * i(k + 1)) – (m * i(k + 1)) / (1 + n * i(k + 1)) – (mu + delta + rho) * i(k + 1)) + …
((beta * s(k) * i(k)) / (1 + gamma * i(k)) – (m * i(k)) / (1 + n * i(k)) – (mu + delta + rho) * i(k)));
dr_corr = h / 2 * (((m * i(k + 1)) / (1 + n * i(k + 1)) + delta * i(k + 1) – mu * r(k + 1)) + …
((m * i(k)) / (1 + n * i(k)) + delta * i(k) – mu * r(k)));
% Update corrected values
s(k + 1) = s(k) + ds_corr;
i(k + 1) = i(k) + di_corr;
r(k + 1) = r(k) + dr_corr;
end
% Plot the results
figure;
plot(time, s, ‘-o’, ‘DisplayName’, ‘s(t)’);
hold on;
plot(time, i, ‘-s’, ‘DisplayName’, ‘i(t)’);
plot(time, r, ‘-d’, ‘DisplayName’, ‘r(t)’);
xlabel(‘Time’);
ylabel(‘Population’);
title(‘Solution of the System of Fractional Differential Equations’);
legend;
grid on;
% Set plot range
xlim([0 30]);
ylim([0 100]);“`
<</matlabcentral/answers/uploaded_files/1745286/fo_M.png>> fde MATLAB Answers — New Questions
Three phase measurement block measuring current lower than expected
I have three controlled current sources connected as a load. The currents sources are used to simulate harmonic currents. I also have three phase filter banks used to filter our the harmonics. I have multiple three measurement blocks all set to phase-to-phase measurements. One measurement block (line) is connected to the transformer secondary. One measurement block (load) connected to the controlled current sources. One measurement block (caps) is connected to the capacitors. I would expect the following line current = load current + capacitor current (see be drawing below). Both the controlled current sources and the capacitors have a significant amount of current flow. Why doesn’t the transformer secondary current = capacitor current + controller current source load?
Here is my controlled current source configuration. The sine waves are populated from a MATLAB data variable.I have three controlled current sources connected as a load. The currents sources are used to simulate harmonic currents. I also have three phase filter banks used to filter our the harmonics. I have multiple three measurement blocks all set to phase-to-phase measurements. One measurement block (line) is connected to the transformer secondary. One measurement block (load) connected to the controlled current sources. One measurement block (caps) is connected to the capacitors. I would expect the following line current = load current + capacitor current (see be drawing below). Both the controlled current sources and the capacitors have a significant amount of current flow. Why doesn’t the transformer secondary current = capacitor current + controller current source load?
Here is my controlled current source configuration. The sine waves are populated from a MATLAB data variable. I have three controlled current sources connected as a load. The currents sources are used to simulate harmonic currents. I also have three phase filter banks used to filter our the harmonics. I have multiple three measurement blocks all set to phase-to-phase measurements. One measurement block (line) is connected to the transformer secondary. One measurement block (load) connected to the controlled current sources. One measurement block (caps) is connected to the capacitors. I would expect the following line current = load current + capacitor current (see be drawing below). Both the controlled current sources and the capacitors have a significant amount of current flow. Why doesn’t the transformer secondary current = capacitor current + controller current source load?
Here is my controlled current source configuration. The sine waves are populated from a MATLAB data variable. current measurement MATLAB Answers — New Questions
How can I create this 2D waterfall plot?
The data is from a CSV file with one time column and 32 columns of data.
The curves show the Amplitude vs. Time behavior of the sensors while the sensor locations (in meters) are placed on the Y-axis.
I assume this is a waterfall plot, but I can’t reproduce it. How can I make a graph like this one?The data is from a CSV file with one time column and 32 columns of data.
The curves show the Amplitude vs. Time behavior of the sensors while the sensor locations (in meters) are placed on the Y-axis.
I assume this is a waterfall plot, but I can’t reproduce it. How can I make a graph like this one? The data is from a CSV file with one time column and 32 columns of data.
The curves show the Amplitude vs. Time behavior of the sensors while the sensor locations (in meters) are placed on the Y-axis.
I assume this is a waterfall plot, but I can’t reproduce it. How can I make a graph like this one? plotting, plot, waterfall, figure MATLAB Answers — New Questions
Index exceeds the number of array elements. Index must not exceed 101.
Please help me fix the following error: "Index exceeds the number of array elements. Index must not exceed 101." thank you very much!
%% Phase plane
clear all
clc
%% conditions
A=[-0.8 0.1;0.15 -0.15];
A_h=[-0.4 0.2;0.1 0.04];
A_d=[0.2 0.5;-0.3 0.05];
A_u=[0.1;-0.1];
A_c=[-76.0089 387.8927;75.3589 -387.9427];
stime=1.0;
endtime=30;
h=0.01;
t=-stime:h:endtime;
N_0=stime/h;
N_1=endtime/h;
N=N_0+N_1;
%bound=110;
for i=1:N+1
if i<=N_0+1;
x1(:,i)=0.05*sin((i-N_0-1)*h);
x2(:,i)=0.05*cos((i-N_0-1)*h);
else
d_1=floor(1.5+0.5*sin(1.5*i*h));
d_2=floor(2+cos(2.5*i*h));
if i<=4
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1));
else
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1)+A_h(1,1)*x1(:,i-d_1-1)+A_h(1,2)*x2(:,i-d_1-1)+(1/2)*(A_d(1,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-d_2)+x1(i-d_2+1)))+A_d(1,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-d_2)+x2(i-d_2+1)))));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1)+A_h(2,1)*x1(:,i-d_1-1)+A_h(2,2)*x2(:,i-d_1-1)+(1/2)*(A_d(2,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-2)+x1(i-3)+x1(i-4)))+A_d(2,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-2)+x2(i-3)+x2(i-4)))));
end
end
end
%% Plotting Graphs
figure
grid on
hold on
box on
plot(t,x1(1,:),’-g’,t,x2(1,:),’r-‘,’linewidth’,2.5)
hold on
xlabel(‘Time (t)’)
%ylabel(‘State responses’)
legend(‘x_{1}(t)’,’x_{2}(t)’);
xlim([0,30]);
ylim([-100,100]);
%Please help me fix the following error: "Index exceeds the number of array elements. Index must not exceed 101." thank you very much!
%% Phase plane
clear all
clc
%% conditions
A=[-0.8 0.1;0.15 -0.15];
A_h=[-0.4 0.2;0.1 0.04];
A_d=[0.2 0.5;-0.3 0.05];
A_u=[0.1;-0.1];
A_c=[-76.0089 387.8927;75.3589 -387.9427];
stime=1.0;
endtime=30;
h=0.01;
t=-stime:h:endtime;
N_0=stime/h;
N_1=endtime/h;
N=N_0+N_1;
%bound=110;
for i=1:N+1
if i<=N_0+1;
x1(:,i)=0.05*sin((i-N_0-1)*h);
x2(:,i)=0.05*cos((i-N_0-1)*h);
else
d_1=floor(1.5+0.5*sin(1.5*i*h));
d_2=floor(2+cos(2.5*i*h));
if i<=4
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1));
else
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1)+A_h(1,1)*x1(:,i-d_1-1)+A_h(1,2)*x2(:,i-d_1-1)+(1/2)*(A_d(1,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-d_2)+x1(i-d_2+1)))+A_d(1,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-d_2)+x2(i-d_2+1)))));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1)+A_h(2,1)*x1(:,i-d_1-1)+A_h(2,2)*x2(:,i-d_1-1)+(1/2)*(A_d(2,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-2)+x1(i-3)+x1(i-4)))+A_d(2,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-2)+x2(i-3)+x2(i-4)))));
end
end
end
%% Plotting Graphs
figure
grid on
hold on
box on
plot(t,x1(1,:),’-g’,t,x2(1,:),’r-‘,’linewidth’,2.5)
hold on
xlabel(‘Time (t)’)
%ylabel(‘State responses’)
legend(‘x_{1}(t)’,’x_{2}(t)’);
xlim([0,30]);
ylim([-100,100]);
% Please help me fix the following error: "Index exceeds the number of array elements. Index must not exceed 101." thank you very much!
%% Phase plane
clear all
clc
%% conditions
A=[-0.8 0.1;0.15 -0.15];
A_h=[-0.4 0.2;0.1 0.04];
A_d=[0.2 0.5;-0.3 0.05];
A_u=[0.1;-0.1];
A_c=[-76.0089 387.8927;75.3589 -387.9427];
stime=1.0;
endtime=30;
h=0.01;
t=-stime:h:endtime;
N_0=stime/h;
N_1=endtime/h;
N=N_0+N_1;
%bound=110;
for i=1:N+1
if i<=N_0+1;
x1(:,i)=0.05*sin((i-N_0-1)*h);
x2(:,i)=0.05*cos((i-N_0-1)*h);
else
d_1=floor(1.5+0.5*sin(1.5*i*h));
d_2=floor(2+cos(2.5*i*h));
if i<=4
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1));
else
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1)+A_h(1,1)*x1(:,i-d_1-1)+A_h(1,2)*x2(:,i-d_1-1)+(1/2)*(A_d(1,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-d_2)+x1(i-d_2+1)))+A_d(1,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-d_2)+x2(i-d_2+1)))));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1)+A_h(2,1)*x1(:,i-d_1-1)+A_h(2,2)*x2(:,i-d_1-1)+(1/2)*(A_d(2,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-2)+x1(i-3)+x1(i-4)))+A_d(2,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-2)+x2(i-3)+x2(i-4)))));
end
end
end
%% Plotting Graphs
figure
grid on
hold on
box on
plot(t,x1(1,:),’-g’,t,x2(1,:),’r-‘,’linewidth’,2.5)
hold on
xlabel(‘Time (t)’)
%ylabel(‘State responses’)
legend(‘x_{1}(t)’,’x_{2}(t)’);
xlim([0,30]);
ylim([-100,100]);
% indexing MATLAB Answers — New Questions
3D simulation engine interface setup timeout.
I am getting this error when i try to run the script in this example Visualize Automated Parking Valet Using Unreal Engine Simulation.
MATLAB System block ‘untitled/Simulation 3D Scene Configuration/Simulation 3D Engine’ error occurred when invoking ‘resetImpl’ method of ‘Simulation3DEngine’. The error was thrown from ‘
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dEngineInterface.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dEngine.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dProject.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dblkssim3dblksSimulation3DEngine.p’ at line 0′.
Caused by:
3D simulation engine interface setup timeout.
Can anyone help me fix this ?I am getting this error when i try to run the script in this example Visualize Automated Parking Valet Using Unreal Engine Simulation.
MATLAB System block ‘untitled/Simulation 3D Scene Configuration/Simulation 3D Engine’ error occurred when invoking ‘resetImpl’ method of ‘Simulation3DEngine’. The error was thrown from ‘
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dEngineInterface.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dEngine.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dProject.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dblkssim3dblksSimulation3DEngine.p’ at line 0′.
Caused by:
3D simulation engine interface setup timeout.
Can anyone help me fix this ? I am getting this error when i try to run the script in this example Visualize Automated Parking Valet Using Unreal Engine Simulation.
MATLAB System block ‘untitled/Simulation 3D Scene Configuration/Simulation 3D Engine’ error occurred when invoking ‘resetImpl’ method of ‘Simulation3DEngine’. The error was thrown from ‘
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dEngineInterface.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dEngine.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dsim3d+sim3dProject.p’ at line 0
‘C:MATLAB2020btoolboxsharedsim3dblkssim3dblksSimulation3DEngine.p’ at line 0′.
Caused by:
3D simulation engine interface setup timeout.
Can anyone help me fix this ? simulink, automated driving toolbox MATLAB Answers — New Questions
RoadRunner plugins for Unreal 4.26
With the new version R2022a the RoadRunner Plugins should support Unreal4.26 and the .udatasmith format. On the download page it still says RoadRunner Plugins 1.1.0 and in the ReadMe it only says "support Unreal 4.25". Is there a newer version somewhere?
So the chain from RoadRunner to Unreal including co-simulation with Simulink doesn’t seem to work for me anymore.With the new version R2022a the RoadRunner Plugins should support Unreal4.26 and the .udatasmith format. On the download page it still says RoadRunner Plugins 1.1.0 and in the ReadMe it only says "support Unreal 4.25". Is there a newer version somewhere?
So the chain from RoadRunner to Unreal including co-simulation with Simulink doesn’t seem to work for me anymore. With the new version R2022a the RoadRunner Plugins should support Unreal4.26 and the .udatasmith format. On the download page it still says RoadRunner Plugins 1.1.0 and in the ReadMe it only says "support Unreal 4.25". Is there a newer version somewhere?
So the chain from RoadRunner to Unreal including co-simulation with Simulink doesn’t seem to work for me anymore. unreal export, unreal interface MATLAB Answers — New Questions
[MATLAB’s GUI] Erase everything within “Delimiter matching”
Hello,
After coming across this post,
https://stackoverflow.com/questions/72543162/color-parentheses-groups-in-matlabs-ide
I improved a lot my Matlab experience by better seeing the scope of a function, it’s arguments, parenthesis, etc. It’s great.
However, I was wondering if there is a way to setup a hotkey to remove the contents that are highlighthed by such delimiters. I couldn’t find anything online.
In other words, if Matlab is properly highlighting these delimiters (i.e. parenthesis, brackets, IF/END, etc) there must be a way to capture these 2 "endpoints" and just erase everything within it. Maybe some Java hacks which I’m not super familiar with?
I’m using Matlab 2020b and have no intention of changing it anytime soon (because I have custom libraries that stopped being supported) if that changes anything.
Thanks for any input!
LucianoHello,
After coming across this post,
https://stackoverflow.com/questions/72543162/color-parentheses-groups-in-matlabs-ide
I improved a lot my Matlab experience by better seeing the scope of a function, it’s arguments, parenthesis, etc. It’s great.
However, I was wondering if there is a way to setup a hotkey to remove the contents that are highlighthed by such delimiters. I couldn’t find anything online.
In other words, if Matlab is properly highlighting these delimiters (i.e. parenthesis, brackets, IF/END, etc) there must be a way to capture these 2 "endpoints" and just erase everything within it. Maybe some Java hacks which I’m not super familiar with?
I’m using Matlab 2020b and have no intention of changing it anytime soon (because I have custom libraries that stopped being supported) if that changes anything.
Thanks for any input!
Luciano Hello,
After coming across this post,
https://stackoverflow.com/questions/72543162/color-parentheses-groups-in-matlabs-ide
I improved a lot my Matlab experience by better seeing the scope of a function, it’s arguments, parenthesis, etc. It’s great.
However, I was wondering if there is a way to setup a hotkey to remove the contents that are highlighthed by such delimiters. I couldn’t find anything online.
In other words, if Matlab is properly highlighting these delimiters (i.e. parenthesis, brackets, IF/END, etc) there must be a way to capture these 2 "endpoints" and just erase everything within it. Maybe some Java hacks which I’m not super familiar with?
I’m using Matlab 2020b and have no intention of changing it anytime soon (because I have custom libraries that stopped being supported) if that changes anything.
Thanks for any input!
Luciano delimiter matching highlight erase gui hotkey, selective highlighting MATLAB Answers — New Questions
How to export from Mathematica so that Matlab can see a variable name other than Expression1
I’m exporting a variable from Mathematica to disk in .mat format.
Later I want to read this in Matlab.
When I load the .mat file, my variable is called Expression1
How do I export it properly in Mathematica so that my original variable name is preserved?
(I don’t know if this is possible. I can’t find out how to do it when I search the mathematica help files)
Thanks,
TomI’m exporting a variable from Mathematica to disk in .mat format.
Later I want to read this in Matlab.
When I load the .mat file, my variable is called Expression1
How do I export it properly in Mathematica so that my original variable name is preserved?
(I don’t know if this is possible. I can’t find out how to do it when I search the mathematica help files)
Thanks,
Tom I’m exporting a variable from Mathematica to disk in .mat format.
Later I want to read this in Matlab.
When I load the .mat file, my variable is called Expression1
How do I export it properly in Mathematica so that my original variable name is preserved?
(I don’t know if this is possible. I can’t find out how to do it when I search the mathematica help files)
Thanks,
Tom export, load, mathematica, variable name MATLAB Answers — New Questions
Who do I contact to receive a New License/Product or a Renewal Quote?
Who do I contact to receive a New License/Product or a Renewal Quote?Who do I contact to receive a New License/Product or a Renewal Quote? Who do I contact to receive a New License/Product or a Renewal Quote? quote, quotation, inquiry, proforma, invoice, request, 見積, 見積り, renewal MATLAB Answers — New Questions
Plotting Sierpinski’s triangle
Sierpinski’s triangle can be implemented in MATLAB by plotting points iteratively according to one of the following three rules which are selected randomly with equal probability.
* Rule 1: x=05.*x y=0.5*y
* Rule 2: x=0.5*x+.25 y=0.5*y+ sqrt(3)/4
* Rule 3: x=0.5x+.5 y=.5*y
Write a script that calculates the x and y vectors and then plots y versus x as individual points.
Start with x1=0 and y1=0. Run the program three times, with 100, 1000, and 10000 iterations. Print all three plots.
I do not know where to start. I am thinking if and for loops but not sure.Sierpinski’s triangle can be implemented in MATLAB by plotting points iteratively according to one of the following three rules which are selected randomly with equal probability.
* Rule 1: x=05.*x y=0.5*y
* Rule 2: x=0.5*x+.25 y=0.5*y+ sqrt(3)/4
* Rule 3: x=0.5x+.5 y=.5*y
Write a script that calculates the x and y vectors and then plots y versus x as individual points.
Start with x1=0 and y1=0. Run the program three times, with 100, 1000, and 10000 iterations. Print all three plots.
I do not know where to start. I am thinking if and for loops but not sure. Sierpinski’s triangle can be implemented in MATLAB by plotting points iteratively according to one of the following three rules which are selected randomly with equal probability.
* Rule 1: x=05.*x y=0.5*y
* Rule 2: x=0.5*x+.25 y=0.5*y+ sqrt(3)/4
* Rule 3: x=0.5x+.5 y=.5*y
Write a script that calculates the x and y vectors and then plots y versus x as individual points.
Start with x1=0 and y1=0. Run the program three times, with 100, 1000, and 10000 iterations. Print all three plots.
I do not know where to start. I am thinking if and for loops but not sure. matlab, homework, doit4me MATLAB Answers — New Questions
Display/highlight specific pixels of in image
לק"י
Hello guys,
A short code was written to allow me to gather data about cells masks that were clicked on in a figure.
I want to simoultaneously show all previous chosen cells with a color or other distinctive way to avoid picking twice the same cell.
Haven’t managed to find or think about easy and quick way to make it happen.
The cells masks are from time series stack that is being iterated for the amount of frames in the stack. All of this process is being iterated for the amount of cells I want to pick, which I specify in a variable before running the code.
the code:
stackfilename = ‘17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’; %get the name of the
% time series stack of masks. These cellpose stacks are handing each cell a unique grayscale value
%ranging from 1 to the total amount of cells detected by cellpose. background (non-mask undetected cell pixels)
% is set to 0.
info = imfinfo(stackfilename); %Info function gets information of every single image of the image stack.
numberOfImages = length(info); %counting the length of info will give the amount of images in the stack.
cellnumber= 6; %Enter the desired amount of cells to be analysed.
pixelindexes={}; %Create a cell array that will hold each mouse click (mask choose) indexes.
pixelvalues={}; %Create a cell array that will hold each mask grayscale value.
for i = 1:cellnumber %The number of cells (number of main loops).
for j=1:numberOfImages %For each cell (main loop), a secondary loop will initiate for the amount…
%of frames in the cells masks stack (‘numberOfImages’).
crntimg = imread(stackfilename, j); % Read the current image
figure(1) %Create a figure
old = double(crntimg); %Turn the image from uint to double for later mathematical manipulation.
crntimgmax=double((max(max(crntimg)))); %Find the max grayscael value of the current frame…
%,equals total cell masks in the frame.
new = 10+(10*(old./crntimgmax)); %Manipulate the image matrix to allow dark tones
% (low values) to be shown with imshow command.
new(new==10)=0; %Set background values to 0 for the dark tones to be seen brighter.
imshow(new,[]) %Display image.
if i~=1 %If previous cells were chosen, start a loop that will…
%plot/show them on the new image that was created to avoid choosing the same cell twice.
hold on %Hold the image.
for k=1:(i-1)
imshow(crntimg==(pixelvalues{j,k}(1)),[]) %|||***This is where
% I can’t figure out how to SIMOULTANEOUSLY SHOW *ALL* OF THE PREVIOUSLY CHOSEN cell masks with
%a DISTINCTIVE COLOR or other way that will set them apart from the other yet unchosen cell masks.***|||
end
end
pixelindexes{j,i}= ginput(1); %Store pixel indexes.
pixelvalues{j,i}=impixel(crntimg,pixelindexes{j,i}(1,1),pixelindexes{j,i}(1,2)); %Store pixel values.
end
close (figure (1))
end
%Save the data
save(append(stackfilename, append…
( append(‘ ‘, strrep(string(datetime(now,’ConvertFrom’,’datenum’)),’:’,’-‘)),’ Worksapce data’)));
The part that I can’t seem to over come is the last for loop which should simoultaneously show all previous chosen masks with a distinctive color or any other way that will show the previously chosen cells distinctively. I tried my best to explain my self and provide with sufficient info. If anything else is needed or needs to be more clear please tell me.
Thanks,
Amit.לק"י
Hello guys,
A short code was written to allow me to gather data about cells masks that were clicked on in a figure.
I want to simoultaneously show all previous chosen cells with a color or other distinctive way to avoid picking twice the same cell.
Haven’t managed to find or think about easy and quick way to make it happen.
The cells masks are from time series stack that is being iterated for the amount of frames in the stack. All of this process is being iterated for the amount of cells I want to pick, which I specify in a variable before running the code.
the code:
stackfilename = ‘17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’; %get the name of the
% time series stack of masks. These cellpose stacks are handing each cell a unique grayscale value
%ranging from 1 to the total amount of cells detected by cellpose. background (non-mask undetected cell pixels)
% is set to 0.
info = imfinfo(stackfilename); %Info function gets information of every single image of the image stack.
numberOfImages = length(info); %counting the length of info will give the amount of images in the stack.
cellnumber= 6; %Enter the desired amount of cells to be analysed.
pixelindexes={}; %Create a cell array that will hold each mouse click (mask choose) indexes.
pixelvalues={}; %Create a cell array that will hold each mask grayscale value.
for i = 1:cellnumber %The number of cells (number of main loops).
for j=1:numberOfImages %For each cell (main loop), a secondary loop will initiate for the amount…
%of frames in the cells masks stack (‘numberOfImages’).
crntimg = imread(stackfilename, j); % Read the current image
figure(1) %Create a figure
old = double(crntimg); %Turn the image from uint to double for later mathematical manipulation.
crntimgmax=double((max(max(crntimg)))); %Find the max grayscael value of the current frame…
%,equals total cell masks in the frame.
new = 10+(10*(old./crntimgmax)); %Manipulate the image matrix to allow dark tones
% (low values) to be shown with imshow command.
new(new==10)=0; %Set background values to 0 for the dark tones to be seen brighter.
imshow(new,[]) %Display image.
if i~=1 %If previous cells were chosen, start a loop that will…
%plot/show them on the new image that was created to avoid choosing the same cell twice.
hold on %Hold the image.
for k=1:(i-1)
imshow(crntimg==(pixelvalues{j,k}(1)),[]) %|||***This is where
% I can’t figure out how to SIMOULTANEOUSLY SHOW *ALL* OF THE PREVIOUSLY CHOSEN cell masks with
%a DISTINCTIVE COLOR or other way that will set them apart from the other yet unchosen cell masks.***|||
end
end
pixelindexes{j,i}= ginput(1); %Store pixel indexes.
pixelvalues{j,i}=impixel(crntimg,pixelindexes{j,i}(1,1),pixelindexes{j,i}(1,2)); %Store pixel values.
end
close (figure (1))
end
%Save the data
save(append(stackfilename, append…
( append(‘ ‘, strrep(string(datetime(now,’ConvertFrom’,’datenum’)),’:’,’-‘)),’ Worksapce data’)));
The part that I can’t seem to over come is the last for loop which should simoultaneously show all previous chosen masks with a distinctive color or any other way that will show the previously chosen cells distinctively. I tried my best to explain my self and provide with sufficient info. If anything else is needed or needs to be more clear please tell me.
Thanks,
Amit. לק"י
Hello guys,
A short code was written to allow me to gather data about cells masks that were clicked on in a figure.
I want to simoultaneously show all previous chosen cells with a color or other distinctive way to avoid picking twice the same cell.
Haven’t managed to find or think about easy and quick way to make it happen.
The cells masks are from time series stack that is being iterated for the amount of frames in the stack. All of this process is being iterated for the amount of cells I want to pick, which I specify in a variable before running the code.
the code:
stackfilename = ‘17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’; %get the name of the
% time series stack of masks. These cellpose stacks are handing each cell a unique grayscale value
%ranging from 1 to the total amount of cells detected by cellpose. background (non-mask undetected cell pixels)
% is set to 0.
info = imfinfo(stackfilename); %Info function gets information of every single image of the image stack.
numberOfImages = length(info); %counting the length of info will give the amount of images in the stack.
cellnumber= 6; %Enter the desired amount of cells to be analysed.
pixelindexes={}; %Create a cell array that will hold each mouse click (mask choose) indexes.
pixelvalues={}; %Create a cell array that will hold each mask grayscale value.
for i = 1:cellnumber %The number of cells (number of main loops).
for j=1:numberOfImages %For each cell (main loop), a secondary loop will initiate for the amount…
%of frames in the cells masks stack (‘numberOfImages’).
crntimg = imread(stackfilename, j); % Read the current image
figure(1) %Create a figure
old = double(crntimg); %Turn the image from uint to double for later mathematical manipulation.
crntimgmax=double((max(max(crntimg)))); %Find the max grayscael value of the current frame…
%,equals total cell masks in the frame.
new = 10+(10*(old./crntimgmax)); %Manipulate the image matrix to allow dark tones
% (low values) to be shown with imshow command.
new(new==10)=0; %Set background values to 0 for the dark tones to be seen brighter.
imshow(new,[]) %Display image.
if i~=1 %If previous cells were chosen, start a loop that will…
%plot/show them on the new image that was created to avoid choosing the same cell twice.
hold on %Hold the image.
for k=1:(i-1)
imshow(crntimg==(pixelvalues{j,k}(1)),[]) %|||***This is where
% I can’t figure out how to SIMOULTANEOUSLY SHOW *ALL* OF THE PREVIOUSLY CHOSEN cell masks with
%a DISTINCTIVE COLOR or other way that will set them apart from the other yet unchosen cell masks.***|||
end
end
pixelindexes{j,i}= ginput(1); %Store pixel indexes.
pixelvalues{j,i}=impixel(crntimg,pixelindexes{j,i}(1,1),pixelindexes{j,i}(1,2)); %Store pixel values.
end
close (figure (1))
end
%Save the data
save(append(stackfilename, append…
( append(‘ ‘, strrep(string(datetime(now,’ConvertFrom’,’datenum’)),’:’,’-‘)),’ Worksapce data’)));
The part that I can’t seem to over come is the last for loop which should simoultaneously show all previous chosen masks with a distinctive color or any other way that will show the previously chosen cells distinctively. I tried my best to explain my self and provide with sufficient info. If anything else is needed or needs to be more clear please tell me.
Thanks,
Amit. matrix manipulation, digital image processing, imshow, overlay images/pixels, multiple imshow MATLAB Answers — New Questions
How can I compile a pre-trained neural network into a standalone application using the MATLAB Compiler 4.10 (R2009a)?
The MATLAB Compiler 4.10 (R2009a) support for MATLAB and Toolboxes at the following web-link suggests that I can compile a pre-trained neural network:
http://www.mathworks.com/products/compiler/compiler_support.htmlThe MATLAB Compiler 4.10 (R2009a) support for MATLAB and Toolboxes at the following web-link suggests that I can compile a pre-trained neural network:
http://www.mathworks.com/products/compiler/compiler_support.html The MATLAB Compiler 4.10 (R2009a) support for MATLAB and Toolboxes at the following web-link suggests that I can compile a pre-trained neural network:
http://www.mathworks.com/products/compiler/compiler_support.html pretrained MATLAB Answers — New Questions
I got an error to the part that used to work no problem. Why?
I didn’t change any of that part, but it suddenly returns shown error.I didn’t change any of that part, but it suddenly returns shown error. I didn’t change any of that part, but it suddenly returns shown error. matlab, error MATLAB Answers — New Questions
Why do I receive “Too many arguments” error when trying to export data from an app designer table as a .txt file, to a user defined file location?
I am attempting to write data from an app designer table, to a .txt file, which can then be saved to a user-specified file location at the touch of a button. It should be noted that the table is quite large, with a length of 16,420 values, so maybe that is causing an issue? Not sure. Here is what I have currently:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
t1=writetable(app.UITable.Data,’Road Profile_fl.txt’);
[file,path] = uiputfile(‘Road Profile_fl.txt’);
save(fullfile(path, file), ‘t1′,’-ascii’)
end
The following errors are returned:
Any advice on how to fix this, or even a different strategy to accomplish the same goal would be much appreciated. Thank you.I am attempting to write data from an app designer table, to a .txt file, which can then be saved to a user-specified file location at the touch of a button. It should be noted that the table is quite large, with a length of 16,420 values, so maybe that is causing an issue? Not sure. Here is what I have currently:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
t1=writetable(app.UITable.Data,’Road Profile_fl.txt’);
[file,path] = uiputfile(‘Road Profile_fl.txt’);
save(fullfile(path, file), ‘t1′,’-ascii’)
end
The following errors are returned:
Any advice on how to fix this, or even a different strategy to accomplish the same goal would be much appreciated. Thank you. I am attempting to write data from an app designer table, to a .txt file, which can then be saved to a user-specified file location at the touch of a button. It should be noted that the table is quite large, with a length of 16,420 values, so maybe that is causing an issue? Not sure. Here is what I have currently:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
t1=writetable(app.UITable.Data,’Road Profile_fl.txt’);
[file,path] = uiputfile(‘Road Profile_fl.txt’);
save(fullfile(path, file), ‘t1′,’-ascii’)
end
The following errors are returned:
Any advice on how to fix this, or even a different strategy to accomplish the same goal would be much appreciated. Thank you. appdesigner, export, txt MATLAB Answers — New Questions
Simscape multibody is not displayed when using show() function
I am working on a project where I have to build a UR5e robot system with Robotique Hand-e gripper. Since the Hand-e gripper is not available in the library, I downloaded the CAD model and converted it into STL format (as a single body, since I just need it for representation). I created a simscape multibody and then the model to the UR5e robot using addSubTree() function.
When i check the rigidBodyTree using showdetails() function the gripper object is added correctly (see image- Body 11). But when I try to visualize the same using show() function the gripper body is not displayed. I can view the model Simscape mechanics explorer without any issues. What am I doing wrong?I am working on a project where I have to build a UR5e robot system with Robotique Hand-e gripper. Since the Hand-e gripper is not available in the library, I downloaded the CAD model and converted it into STL format (as a single body, since I just need it for representation). I created a simscape multibody and then the model to the UR5e robot using addSubTree() function.
When i check the rigidBodyTree using showdetails() function the gripper object is added correctly (see image- Body 11). But when I try to visualize the same using show() function the gripper body is not displayed. I can view the model Simscape mechanics explorer without any issues. What am I doing wrong? I am working on a project where I have to build a UR5e robot system with Robotique Hand-e gripper. Since the Hand-e gripper is not available in the library, I downloaded the CAD model and converted it into STL format (as a single body, since I just need it for representation). I created a simscape multibody and then the model to the UR5e robot using addSubTree() function.
When i check the rigidBodyTree using showdetails() function the gripper object is added correctly (see image- Body 11). But when I try to visualize the same using show() function the gripper body is not displayed. I can view the model Simscape mechanics explorer without any issues. What am I doing wrong? robotics toolbox, simscape multibody MATLAB Answers — New Questions