Category: Matlab
Category Archives: Matlab
Find Eigenvalues of ODE45 Solution MATLAB
I have the following non-linear ODE:
I have the following ODE45 solution:
fun = @(t,X)odefun(X,K,C,M,F(t),resSize);
[t_ode,X_answer] = ode45(fun,tspan,X_0);
The input matrices are stiffness K(X), damping C, mass M, and force F. resSize is the total number of masses in the system.
I would like to find the system’s eigenvalues using either the Jacobian matrix, transfer function, or any other viable method.
I have tried using:
[vector,lambda,condition_number] = polyeig(K(X_answer),C,M);
This is tricky since my K matrix is a function handle of X. In other words, K=@(X). X represents a displacement vector of each mass in the system (x_1(t),x_2(t),…x_resSize(t)), where resSize is the total number of masses. My X_answer matrix is a double with dimensions of t_ode by resSize, where each row is the displacement vector of each mass in double form. Is there some way to substitute X_answer into my function handle for K so I can use polyeig()? If not, how would I go about finding my system’s transfer function or Jacobian matrix so that I can find it’s eigenvalues?I have the following non-linear ODE:
I have the following ODE45 solution:
fun = @(t,X)odefun(X,K,C,M,F(t),resSize);
[t_ode,X_answer] = ode45(fun,tspan,X_0);
The input matrices are stiffness K(X), damping C, mass M, and force F. resSize is the total number of masses in the system.
I would like to find the system’s eigenvalues using either the Jacobian matrix, transfer function, or any other viable method.
I have tried using:
[vector,lambda,condition_number] = polyeig(K(X_answer),C,M);
This is tricky since my K matrix is a function handle of X. In other words, K=@(X). X represents a displacement vector of each mass in the system (x_1(t),x_2(t),…x_resSize(t)), where resSize is the total number of masses. My X_answer matrix is a double with dimensions of t_ode by resSize, where each row is the displacement vector of each mass in double form. Is there some way to substitute X_answer into my function handle for K so I can use polyeig()? If not, how would I go about finding my system’s transfer function or Jacobian matrix so that I can find it’s eigenvalues? I have the following non-linear ODE:
I have the following ODE45 solution:
fun = @(t,X)odefun(X,K,C,M,F(t),resSize);
[t_ode,X_answer] = ode45(fun,tspan,X_0);
The input matrices are stiffness K(X), damping C, mass M, and force F. resSize is the total number of masses in the system.
I would like to find the system’s eigenvalues using either the Jacobian matrix, transfer function, or any other viable method.
I have tried using:
[vector,lambda,condition_number] = polyeig(K(X_answer),C,M);
This is tricky since my K matrix is a function handle of X. In other words, K=@(X). X represents a displacement vector of each mass in the system (x_1(t),x_2(t),…x_resSize(t)), where resSize is the total number of masses. My X_answer matrix is a double with dimensions of t_ode by resSize, where each row is the displacement vector of each mass in double form. Is there some way to substitute X_answer into my function handle for K so I can use polyeig()? If not, how would I go about finding my system’s transfer function or Jacobian matrix so that I can find it’s eigenvalues? function, ode45, transfer function, matlab MATLAB Answers — New Questions
ExperienceBufferLength in Reinforcement Learning Toolbox
Hello, everyone,
I found a problem with the ‘ExperienceBufferLength’ property in ‘rlDDPGAgentOptions’ when specifying options for rl agents.
Usually this property is set as 1e6 in the examples of the Help documentation, such as here.
In this example, every episode has 600 (60/0.1) steps. Does the agent start to train when the experience buffer is filled up with the experiences (S,A,R,S’). If so, it would take at least 1667 (1000000/600 ) episodes before the agent starts to improve.
So I want to know how to determine this value.Hello, everyone,
I found a problem with the ‘ExperienceBufferLength’ property in ‘rlDDPGAgentOptions’ when specifying options for rl agents.
Usually this property is set as 1e6 in the examples of the Help documentation, such as here.
In this example, every episode has 600 (60/0.1) steps. Does the agent start to train when the experience buffer is filled up with the experiences (S,A,R,S’). If so, it would take at least 1667 (1000000/600 ) episodes before the agent starts to improve.
So I want to know how to determine this value. Hello, everyone,
I found a problem with the ‘ExperienceBufferLength’ property in ‘rlDDPGAgentOptions’ when specifying options for rl agents.
Usually this property is set as 1e6 in the examples of the Help documentation, such as here.
In this example, every episode has 600 (60/0.1) steps. Does the agent start to train when the experience buffer is filled up with the experiences (S,A,R,S’). If so, it would take at least 1667 (1000000/600 ) episodes before the agent starts to improve.
So I want to know how to determine this value. reinforcement learning, ddpg, experiencebufferlength MATLAB Answers — New Questions
Error using fmincon and integral2: taking integral variables theta and p as an array while performing computation
I am minimizing q for whole range of p and theta; p has limit from 2pi to 20pi and theta from 0 to pi; to find the value of d, r_g,G_g. q is function of theta, p,d, r_g, G_g.
But while computation p and theta are behaving as an array. Because of this I am getting error. I tried using "ArrayValued", true. This is also not working. How to correct this. Here my part of code
[q] = optimizeParameters();% Call optimizeParameters to define the objective function q
options = optimset(‘PlotFcns’, @optimplotfval);% Set optimization options
d0 = [-0.5, 24, 3e6];
lb = [-1, 24, 2e6];
ub = [0, 32, 6e6];
[solution,fval] = fmincon(@(x)integral2(@(theta,p)q(theta,p,x(1),x(2),x(3)),pi/36,pi/6,2*pi,20*pi),d0,[],[],[],[],lb,ub,[],options); % minimize
function q = optimizeParameters()
Vs = 250;
k = @(p)p/Vs;
c = @(theta)Vs./sin(theta);
w5 = 0.001;
n = 3;
dl = -6;
d1 = @(d)dl + 2 * n * d – d;
q = @(theta, p, d, r_g, G_g) calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
end
function answer = calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
% printing the p and thetahere which is giving an array because of this error in further computation
theta
p
% rest of the code
endI am minimizing q for whole range of p and theta; p has limit from 2pi to 20pi and theta from 0 to pi; to find the value of d, r_g,G_g. q is function of theta, p,d, r_g, G_g.
But while computation p and theta are behaving as an array. Because of this I am getting error. I tried using "ArrayValued", true. This is also not working. How to correct this. Here my part of code
[q] = optimizeParameters();% Call optimizeParameters to define the objective function q
options = optimset(‘PlotFcns’, @optimplotfval);% Set optimization options
d0 = [-0.5, 24, 3e6];
lb = [-1, 24, 2e6];
ub = [0, 32, 6e6];
[solution,fval] = fmincon(@(x)integral2(@(theta,p)q(theta,p,x(1),x(2),x(3)),pi/36,pi/6,2*pi,20*pi),d0,[],[],[],[],lb,ub,[],options); % minimize
function q = optimizeParameters()
Vs = 250;
k = @(p)p/Vs;
c = @(theta)Vs./sin(theta);
w5 = 0.001;
n = 3;
dl = -6;
d1 = @(d)dl + 2 * n * d – d;
q = @(theta, p, d, r_g, G_g) calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
end
function answer = calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
% printing the p and thetahere which is giving an array because of this error in further computation
theta
p
% rest of the code
end I am minimizing q for whole range of p and theta; p has limit from 2pi to 20pi and theta from 0 to pi; to find the value of d, r_g,G_g. q is function of theta, p,d, r_g, G_g.
But while computation p and theta are behaving as an array. Because of this I am getting error. I tried using "ArrayValued", true. This is also not working. How to correct this. Here my part of code
[q] = optimizeParameters();% Call optimizeParameters to define the objective function q
options = optimset(‘PlotFcns’, @optimplotfval);% Set optimization options
d0 = [-0.5, 24, 3e6];
lb = [-1, 24, 2e6];
ub = [0, 32, 6e6];
[solution,fval] = fmincon(@(x)integral2(@(theta,p)q(theta,p,x(1),x(2),x(3)),pi/36,pi/6,2*pi,20*pi),d0,[],[],[],[],lb,ub,[],options); % minimize
function q = optimizeParameters()
Vs = 250;
k = @(p)p/Vs;
c = @(theta)Vs./sin(theta);
w5 = 0.001;
n = 3;
dl = -6;
d1 = @(d)dl + 2 * n * d – d;
q = @(theta, p, d, r_g, G_g) calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
end
function answer = calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
% printing the p and thetahere which is giving an array because of this error in further computation
theta
p
% rest of the code
end integral2, fmicon, arrayvalued MATLAB Answers — New Questions
constrainted regularization to solve ill conditioned problems?
I am trying to solve a matrix equation of the form Ax = b (solving for x with known A and b).
prior to trying regularisation I was using lsqlin (https://uk.mathworks.com/help/optim/ug/lsqlin.html) with the constraints lsqlin(C,d,[],[],[],[],lb,ub) where lb and ub are lower and upper bounds for the allowed values of my output vector. Some (but not all) of my vector values in x should not have negative values. My results are ill-conditioned. I was wondering if anyone is aware of any type of regularisation (e.g. Tikhonov) that has lb or ub constraints such that I can make some (but not all) of my values in x non-negative?
For context:
I have tried using Tikhonov regularisation (the example code given here: https://uk.mathworks.com/matlabcentral/fileexchange/130259-arls-automatically-regularized-least-squares?s_tid=prof_contriblnk – the response from 15 Mar 2024). The issue is that this code does not have any constraints.I am trying to solve a matrix equation of the form Ax = b (solving for x with known A and b).
prior to trying regularisation I was using lsqlin (https://uk.mathworks.com/help/optim/ug/lsqlin.html) with the constraints lsqlin(C,d,[],[],[],[],lb,ub) where lb and ub are lower and upper bounds for the allowed values of my output vector. Some (but not all) of my vector values in x should not have negative values. My results are ill-conditioned. I was wondering if anyone is aware of any type of regularisation (e.g. Tikhonov) that has lb or ub constraints such that I can make some (but not all) of my values in x non-negative?
For context:
I have tried using Tikhonov regularisation (the example code given here: https://uk.mathworks.com/matlabcentral/fileexchange/130259-arls-automatically-regularized-least-squares?s_tid=prof_contriblnk – the response from 15 Mar 2024). The issue is that this code does not have any constraints. I am trying to solve a matrix equation of the form Ax = b (solving for x with known A and b).
prior to trying regularisation I was using lsqlin (https://uk.mathworks.com/help/optim/ug/lsqlin.html) with the constraints lsqlin(C,d,[],[],[],[],lb,ub) where lb and ub are lower and upper bounds for the allowed values of my output vector. Some (but not all) of my vector values in x should not have negative values. My results are ill-conditioned. I was wondering if anyone is aware of any type of regularisation (e.g. Tikhonov) that has lb or ub constraints such that I can make some (but not all) of my values in x non-negative?
For context:
I have tried using Tikhonov regularisation (the example code given here: https://uk.mathworks.com/matlabcentral/fileexchange/130259-arls-automatically-regularized-least-squares?s_tid=prof_contriblnk – the response from 15 Mar 2024). The issue is that this code does not have any constraints. tikhonov, regularisation, ill-conditioned, ill conditioned, matrix equation, constraints, constrained equations MATLAB Answers — New Questions
Raspberry Pi 5 Setup – MATLAB Support Package
I just acquired the new Raspberry Pi 5, and wanted to connect to it through MATLAB. I’m using MATLAB 2021b, and followed the steps in setting up the Support package page for Raspberry Pi hardware. However, when I am asked to select a board there is no option for the Raspberry Pi 5 model, which prompts to me to think that’s not yet supported. Is this the case?I just acquired the new Raspberry Pi 5, and wanted to connect to it through MATLAB. I’m using MATLAB 2021b, and followed the steps in setting up the Support package page for Raspberry Pi hardware. However, when I am asked to select a board there is no option for the Raspberry Pi 5 model, which prompts to me to think that’s not yet supported. Is this the case? I just acquired the new Raspberry Pi 5, and wanted to connect to it through MATLAB. I’m using MATLAB 2021b, and followed the steps in setting up the Support package page for Raspberry Pi hardware. However, when I am asked to select a board there is no option for the Raspberry Pi 5 model, which prompts to me to think that’s not yet supported. Is this the case? #pi5, #supportpackage MATLAB Answers — New Questions
Thermal conductivity varying with temperature shows error: Matrix is too large to convert to linear index.
I am solving a steady state thermal model and want to vary thermal conductivity as a function of temperature for materials present in the model.
I have used
kp = @(location,state) 0.3049+0.006197*state.u-(1.153*10^-5)*(state.u).^2+(1.034*10^-8)*(state.u).^3-(3.352*10^-12)*(state.u).^4; % as function for variable thermal conductivity.
thermalProperties(model,"ThermalConductivity",kp,…
"Face", FaceID); % specific faces are assigned variable thermal conductivity
While solving model slover throws following error:
Matrix is too large to convert to linear index.
Error in pde.DiscretizedPDEModel/checkSpatialCoefsForUDependence (line 73)
self.cu = any(isnan(femat.K(:)));
Error in pde.DiscretizedPDEModel (line 36)
obj = obj.checkSpatialCoefsForUDependence(u0,tdummy);
Error in pde.ThermalModel/solve (line 139)
femodel = pde.DiscretizedPDEModel(self,p,e,t,coefstruct,u0,constCoeffsBCs);
Error in thermal_model_vary_pore_OL_limit_2_phase_updated (line 152)
results = solve(model);
The whole code is too long and uses 4-5 function to run 🙁
I have tried reducing the function for variable thermal conductivity to just linear (removing non-linear dependence on themperature) but it shows the same error.
Thanks in advance!I am solving a steady state thermal model and want to vary thermal conductivity as a function of temperature for materials present in the model.
I have used
kp = @(location,state) 0.3049+0.006197*state.u-(1.153*10^-5)*(state.u).^2+(1.034*10^-8)*(state.u).^3-(3.352*10^-12)*(state.u).^4; % as function for variable thermal conductivity.
thermalProperties(model,"ThermalConductivity",kp,…
"Face", FaceID); % specific faces are assigned variable thermal conductivity
While solving model slover throws following error:
Matrix is too large to convert to linear index.
Error in pde.DiscretizedPDEModel/checkSpatialCoefsForUDependence (line 73)
self.cu = any(isnan(femat.K(:)));
Error in pde.DiscretizedPDEModel (line 36)
obj = obj.checkSpatialCoefsForUDependence(u0,tdummy);
Error in pde.ThermalModel/solve (line 139)
femodel = pde.DiscretizedPDEModel(self,p,e,t,coefstruct,u0,constCoeffsBCs);
Error in thermal_model_vary_pore_OL_limit_2_phase_updated (line 152)
results = solve(model);
The whole code is too long and uses 4-5 function to run 🙁
I have tried reducing the function for variable thermal conductivity to just linear (removing non-linear dependence on themperature) but it shows the same error.
Thanks in advance! I am solving a steady state thermal model and want to vary thermal conductivity as a function of temperature for materials present in the model.
I have used
kp = @(location,state) 0.3049+0.006197*state.u-(1.153*10^-5)*(state.u).^2+(1.034*10^-8)*(state.u).^3-(3.352*10^-12)*(state.u).^4; % as function for variable thermal conductivity.
thermalProperties(model,"ThermalConductivity",kp,…
"Face", FaceID); % specific faces are assigned variable thermal conductivity
While solving model slover throws following error:
Matrix is too large to convert to linear index.
Error in pde.DiscretizedPDEModel/checkSpatialCoefsForUDependence (line 73)
self.cu = any(isnan(femat.K(:)));
Error in pde.DiscretizedPDEModel (line 36)
obj = obj.checkSpatialCoefsForUDependence(u0,tdummy);
Error in pde.ThermalModel/solve (line 139)
femodel = pde.DiscretizedPDEModel(self,p,e,t,coefstruct,u0,constCoeffsBCs);
Error in thermal_model_vary_pore_OL_limit_2_phase_updated (line 152)
results = solve(model);
The whole code is too long and uses 4-5 function to run 🙁
I have tried reducing the function for variable thermal conductivity to just linear (removing non-linear dependence on themperature) but it shows the same error.
Thanks in advance! thermal model, variable thermal conductivity, pde, function, large matrices, fem MATLAB Answers — New Questions
How do I create and place a non-uniform heat flux (Gaussian) on a cylinder with a center hole?
I’m trying to add a non-uniform heat flux to my simple model of a cylinder with a center hole. I know I need to create a function that describes the heat flux (Gaussian) but not sure how to do that in the context of my model. I believe the function can be applied as a thermalBC to Face 2 as shown below.
T_initial = 20;
t_end = 100;
model=createpde(‘thermal’,’transient’);
geo = multicylcinder([.3,2],.2,’void’,[1,0]);
modelGeometry = geo;
pdegplot(model,’FaceLabels’,on);
thermalProperties(model,’ThermalConductivity’,4,’MassDensity’,210,’SpecificHeat’,73);
thermalIC(model,T_initial);
% Heat Flux Function
% ——————
% function Qflux = @nonUniformHeatFlux
% ???
% ???
% ???
% end
thermalBC(model,’Face’,1,’Temperature’,20);
thermalBC(model,’Face’,2,’HeatFlux’,@nonUniformHeatFlux)
generateMesh(model)
pdemesh(model)
tlist = 0:10:t_end
modelresults = solve(model, tlist)
endI’m trying to add a non-uniform heat flux to my simple model of a cylinder with a center hole. I know I need to create a function that describes the heat flux (Gaussian) but not sure how to do that in the context of my model. I believe the function can be applied as a thermalBC to Face 2 as shown below.
T_initial = 20;
t_end = 100;
model=createpde(‘thermal’,’transient’);
geo = multicylcinder([.3,2],.2,’void’,[1,0]);
modelGeometry = geo;
pdegplot(model,’FaceLabels’,on);
thermalProperties(model,’ThermalConductivity’,4,’MassDensity’,210,’SpecificHeat’,73);
thermalIC(model,T_initial);
% Heat Flux Function
% ——————
% function Qflux = @nonUniformHeatFlux
% ???
% ???
% ???
% end
thermalBC(model,’Face’,1,’Temperature’,20);
thermalBC(model,’Face’,2,’HeatFlux’,@nonUniformHeatFlux)
generateMesh(model)
pdemesh(model)
tlist = 0:10:t_end
modelresults = solve(model, tlist)
end I’m trying to add a non-uniform heat flux to my simple model of a cylinder with a center hole. I know I need to create a function that describes the heat flux (Gaussian) but not sure how to do that in the context of my model. I believe the function can be applied as a thermalBC to Face 2 as shown below.
T_initial = 20;
t_end = 100;
model=createpde(‘thermal’,’transient’);
geo = multicylcinder([.3,2],.2,’void’,[1,0]);
modelGeometry = geo;
pdegplot(model,’FaceLabels’,on);
thermalProperties(model,’ThermalConductivity’,4,’MassDensity’,210,’SpecificHeat’,73);
thermalIC(model,T_initial);
% Heat Flux Function
% ——————
% function Qflux = @nonUniformHeatFlux
% ???
% ???
% ???
% end
thermalBC(model,’Face’,1,’Temperature’,20);
thermalBC(model,’Face’,2,’HeatFlux’,@nonUniformHeatFlux)
generateMesh(model)
pdemesh(model)
tlist = 0:10:t_end
modelresults = solve(model, tlist)
end thermal analysis, nonuniform-heat flux MATLAB Answers — New Questions
How to use a variable from script in a function that is in another script
Hello, I am coding a 2nd order differential solver and need to call a variable from the main script into a function script as shown below. I have tried using global however I have read that it is not accepted practice. Also note x2 and x3 are stored in another script called solver.m. Thank you!
fx2x3.m:
function dv3dt = fx2x3 (x2,x3)
dv3dt = ((k3)/(m3))*(x2-x3); %numbers substituted immediately to reduce lines
endHello, I am coding a 2nd order differential solver and need to call a variable from the main script into a function script as shown below. I have tried using global however I have read that it is not accepted practice. Also note x2 and x3 are stored in another script called solver.m. Thank you!
fx2x3.m:
function dv3dt = fx2x3 (x2,x3)
dv3dt = ((k3)/(m3))*(x2-x3); %numbers substituted immediately to reduce lines
end Hello, I am coding a 2nd order differential solver and need to call a variable from the main script into a function script as shown below. I have tried using global however I have read that it is not accepted practice. Also note x2 and x3 are stored in another script called solver.m. Thank you!
fx2x3.m:
function dv3dt = fx2x3 (x2,x3)
dv3dt = ((k3)/(m3))*(x2-x3); %numbers substituted immediately to reduce lines
end matlab code MATLAB Answers — New Questions
Squeeze some part of a plot
Hi, I’d like to squeze the above part of my plot so that the part after the break is 40% of the total y-axis and the below part is 60%. Is it possible to do that? Thank you very much.Hi, I’d like to squeze the above part of my plot so that the part after the break is 40% of the total y-axis and the below part is 60%. Is it possible to do that? Thank you very much. Hi, I’d like to squeze the above part of my plot so that the part after the break is 40% of the total y-axis and the below part is 60%. Is it possible to do that? Thank you very much. plotting, unproportianate axis MATLAB Answers — New Questions
uifigure() laggy with multiple axes, figure() does not support scrollable components
I made an interface to display data from multiple measurement channels. It’s using a Grid Layout Manager, so the first column with fixed pixel width contains channel options, and the second column with "1x" width has axes displaying data. It is Y-scrollable so it can display many channels no matter the window size.
But it gets laggy and possibly unusable when displaying just 10 channels. But I actually found that displaying the same amount of channels in a figure() window is not laggy at all.
But figure() does not support Grid Layout Manager, nor scrollable uipanel…
nb_points = 50e3;
nb_linesperaxes = 1;
nb_axes = 15;
fig = figure("Name","figure()");
fig_ax = arrayfun(@(k)axes(fig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
fig_ax,’UniformOutput’,false);
linkaxes(fig_ax,’x’)
zoom(fig_ax(1),’xon’)
pan(fig_ax(2),’xon’)
uifig = uifigure("Name","uifigure()");
uifig_ax = arrayfun(@(k)axes(uifig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
uifig_ax,’UniformOutput’,false);
linkaxes(uifig_ax,’x’)
zoom(uifig_ax(1),’xon’)
pan(uifig_ax(2),’xon’)
The figure() window works wells, whereas the uifigure() window is laggy. Once compiled as app, it’s even unusable on some not-too-old computers.
Is there an alternative to Grid Layout Manager or scrollable Panel for figure() windows ?
Is there any way to prevent uifigure() window being this laggy ?I made an interface to display data from multiple measurement channels. It’s using a Grid Layout Manager, so the first column with fixed pixel width contains channel options, and the second column with "1x" width has axes displaying data. It is Y-scrollable so it can display many channels no matter the window size.
But it gets laggy and possibly unusable when displaying just 10 channels. But I actually found that displaying the same amount of channels in a figure() window is not laggy at all.
But figure() does not support Grid Layout Manager, nor scrollable uipanel…
nb_points = 50e3;
nb_linesperaxes = 1;
nb_axes = 15;
fig = figure("Name","figure()");
fig_ax = arrayfun(@(k)axes(fig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
fig_ax,’UniformOutput’,false);
linkaxes(fig_ax,’x’)
zoom(fig_ax(1),’xon’)
pan(fig_ax(2),’xon’)
uifig = uifigure("Name","uifigure()");
uifig_ax = arrayfun(@(k)axes(uifig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
uifig_ax,’UniformOutput’,false);
linkaxes(uifig_ax,’x’)
zoom(uifig_ax(1),’xon’)
pan(uifig_ax(2),’xon’)
The figure() window works wells, whereas the uifigure() window is laggy. Once compiled as app, it’s even unusable on some not-too-old computers.
Is there an alternative to Grid Layout Manager or scrollable Panel for figure() windows ?
Is there any way to prevent uifigure() window being this laggy ? I made an interface to display data from multiple measurement channels. It’s using a Grid Layout Manager, so the first column with fixed pixel width contains channel options, and the second column with "1x" width has axes displaying data. It is Y-scrollable so it can display many channels no matter the window size.
But it gets laggy and possibly unusable when displaying just 10 channels. But I actually found that displaying the same amount of channels in a figure() window is not laggy at all.
But figure() does not support Grid Layout Manager, nor scrollable uipanel…
nb_points = 50e3;
nb_linesperaxes = 1;
nb_axes = 15;
fig = figure("Name","figure()");
fig_ax = arrayfun(@(k)axes(fig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
fig_ax,’UniformOutput’,false);
linkaxes(fig_ax,’x’)
zoom(fig_ax(1),’xon’)
pan(fig_ax(2),’xon’)
uifig = uifigure("Name","uifigure()");
uifig_ax = arrayfun(@(k)axes(uifig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
uifig_ax,’UniformOutput’,false);
linkaxes(uifig_ax,’x’)
zoom(uifig_ax(1),’xon’)
pan(uifig_ax(2),’xon’)
The figure() window works wells, whereas the uifigure() window is laggy. Once compiled as app, it’s even unusable on some not-too-old computers.
Is there an alternative to Grid Layout Manager or scrollable Panel for figure() windows ?
Is there any way to prevent uifigure() window being this laggy ? figure, uifigure, performance, laggy, scrollable, grid layout manager MATLAB Answers — New Questions
MATLAB Coder: Why am I receiving Invalid MEX-file error when trying to load a TensorFlowLite model with loadTFLiteModel after upgrading to Update 1 of R2024a release?
I’m using MATLAB Coder and I upgrade to Update 1 of R2024a release. When I try to use the loadTFLiteModel API using the Deep Learning Toolbox Interface for TensorFlow Lite support package, I encounter a strange error (Invalid MEX-file).
What does this error message mean?I’m using MATLAB Coder and I upgrade to Update 1 of R2024a release. When I try to use the loadTFLiteModel API using the Deep Learning Toolbox Interface for TensorFlow Lite support package, I encounter a strange error (Invalid MEX-file).
What does this error message mean? I’m using MATLAB Coder and I upgrade to Update 1 of R2024a release. When I try to use the loadTFLiteModel API using the Deep Learning Toolbox Interface for TensorFlow Lite support package, I encounter a strange error (Invalid MEX-file).
What does this error message mean? neural network, deep learning, matlab coder, code generation, tensorflow, tensorflow-lite, coder-tips MATLAB Answers — New Questions
Unable to run Simulink simulation
I used FilterDesigner to create a banpass filter. I have imported it in Simulink and connected to a chirp block and a spectrum analyzer.
I have quantized the filter inputs and outputs. When I try to simulate, I get the following error:
Expected a GP/Channel-In block to be connected to an input pin in [bandpass3_bandpass3], but instead found block ["Input Quantizer"].I used FilterDesigner to create a banpass filter. I have imported it in Simulink and connected to a chirp block and a spectrum analyzer.
I have quantized the filter inputs and outputs. When I try to simulate, I get the following error:
Expected a GP/Channel-In block to be connected to an input pin in [bandpass3_bandpass3], but instead found block ["Input Quantizer"]. I used FilterDesigner to create a banpass filter. I have imported it in Simulink and connected to a chirp block and a spectrum analyzer.
I have quantized the filter inputs and outputs. When I try to simulate, I get the following error:
Expected a GP/Channel-In block to be connected to an input pin in [bandpass3_bandpass3], but instead found block ["Input Quantizer"]. quantization, filter MATLAB Answers — New Questions
which difference scheme is used in pdepe explicit, implicit, three-layer or symmetric?
which difference scheme is used in pdepe explicit, implicit, three-layer or symmetric? I was asked a question during the course work defense , but I can ‘t find the answer anywhere.which difference scheme is used in pdepe explicit, implicit, three-layer or symmetric? I was asked a question during the course work defense , but I can ‘t find the answer anywhere. which difference scheme is used in pdepe explicit, implicit, three-layer or symmetric? I was asked a question during the course work defense , but I can ‘t find the answer anywhere. difference scheme, pdepe MATLAB Answers — New Questions
How to filter rows from excel in matlab
Hi, I am working on a project and I need this small help. I am currently observing the average speed for cars during weekdays and weekends. Now I have an excel sheet and imported all of the data as column vectors, observation number, time, date, day of the week, average speed of a car, that sort of thing. Now here is where I am stuck. I need to classify or lets say filter all the observations as either weekday or weekend refer to the screenshot for how the excel looks like. so how can I classify the observation as a weekday or weekendHi, I am working on a project and I need this small help. I am currently observing the average speed for cars during weekdays and weekends. Now I have an excel sheet and imported all of the data as column vectors, observation number, time, date, day of the week, average speed of a car, that sort of thing. Now here is where I am stuck. I need to classify or lets say filter all the observations as either weekday or weekend refer to the screenshot for how the excel looks like. so how can I classify the observation as a weekday or weekend Hi, I am working on a project and I need this small help. I am currently observing the average speed for cars during weekdays and weekends. Now I have an excel sheet and imported all of the data as column vectors, observation number, time, date, day of the week, average speed of a car, that sort of thing. Now here is where I am stuck. I need to classify or lets say filter all the observations as either weekday or weekend refer to the screenshot for how the excel looks like. so how can I classify the observation as a weekday or weekend excel, importing excel data, statistics MATLAB Answers — New Questions
Interpolation of matrices with data points having changing derivative
Dear all,
I am trying to define a spline for a set of data whose derivative goes to zero after a certain set of time. Then I have to use this spline for interpolation in a for loop using ppval. But the problem is that in reality the derivative of the spline approaches to zero but the defined spline goes on increasing. At the start both values are matching, the actual and the spline but at larger values the deviation is greater.
In actual scenario, at approximately 20 value at the x axis, the y axis value keeps on increasing, but after that the y value remain approximately constant, even if x-axis value goes to infinity.
Thank you for your response in advance.
RegardsDear all,
I am trying to define a spline for a set of data whose derivative goes to zero after a certain set of time. Then I have to use this spline for interpolation in a for loop using ppval. But the problem is that in reality the derivative of the spline approaches to zero but the defined spline goes on increasing. At the start both values are matching, the actual and the spline but at larger values the deviation is greater.
In actual scenario, at approximately 20 value at the x axis, the y axis value keeps on increasing, but after that the y value remain approximately constant, even if x-axis value goes to infinity.
Thank you for your response in advance.
Regards Dear all,
I am trying to define a spline for a set of data whose derivative goes to zero after a certain set of time. Then I have to use this spline for interpolation in a for loop using ppval. But the problem is that in reality the derivative of the spline approaches to zero but the defined spline goes on increasing. At the start both values are matching, the actual and the spline but at larger values the deviation is greater.
In actual scenario, at approximately 20 value at the x axis, the y axis value keeps on increasing, but after that the y value remain approximately constant, even if x-axis value goes to infinity.
Thank you for your response in advance.
Regards interpolation, matlab, spline MATLAB Answers — New Questions
If Else problem Valid_date code.
Write a function called valid_date that takes three positive integer scalar inputs year, month, day. If these three represent a valid date, return a logical true, otherwise false. The name of the output argument is valid. If any of the inputs is not a positive integer scalar, return false as well. Note that every year that is exactly divisible by 4 is a leap year, except for years that are exactly divisible by 100. However, years that are exactly divisible by 400 are also leap years. For example, the year 1900 was not leap year, but the year 2000 was. Note that your solution must not contain any of the date related built-in MATLAB functions.
So ive seen other peoples code and ive been trying to get it on my own but to no luck fails all test but non-scalar and random non-leap years
function [valid] = valid_date(year, month, day);
leap_year = false;
valid = true;
if nargin ~= 3
valid = false;
else
end
if isscalar(year) && isscalar(month) && isscalar(day)
%%if isinteger(year) && isinteger(month) && isinteger(day)
if (year>=0) && (13>month>0) && (32>day>0)
%%fix(year), fix(month), fix(day)
if month == 2 && day == 29
leap_year = true;
elseif rem(year,400) == 0
leap_year = true;
elseif rem(year,4) == 0 && rem(year,100) ~= 0
leap_year = true;
else
leap_year = false;
end
if month ~= 1 || month ~= 3 || month ~= 5 || month ~= 7 || month ~= 9 month ~= 12 && day == 31
valid = false;
elseif month == 2 && day > 29
valid = false;
end
else
valid = false;
end
else
valid = false;
endWrite a function called valid_date that takes three positive integer scalar inputs year, month, day. If these three represent a valid date, return a logical true, otherwise false. The name of the output argument is valid. If any of the inputs is not a positive integer scalar, return false as well. Note that every year that is exactly divisible by 4 is a leap year, except for years that are exactly divisible by 100. However, years that are exactly divisible by 400 are also leap years. For example, the year 1900 was not leap year, but the year 2000 was. Note that your solution must not contain any of the date related built-in MATLAB functions.
So ive seen other peoples code and ive been trying to get it on my own but to no luck fails all test but non-scalar and random non-leap years
function [valid] = valid_date(year, month, day);
leap_year = false;
valid = true;
if nargin ~= 3
valid = false;
else
end
if isscalar(year) && isscalar(month) && isscalar(day)
%%if isinteger(year) && isinteger(month) && isinteger(day)
if (year>=0) && (13>month>0) && (32>day>0)
%%fix(year), fix(month), fix(day)
if month == 2 && day == 29
leap_year = true;
elseif rem(year,400) == 0
leap_year = true;
elseif rem(year,4) == 0 && rem(year,100) ~= 0
leap_year = true;
else
leap_year = false;
end
if month ~= 1 || month ~= 3 || month ~= 5 || month ~= 7 || month ~= 9 month ~= 12 && day == 31
valid = false;
elseif month == 2 && day > 29
valid = false;
end
else
valid = false;
end
else
valid = false;
end Write a function called valid_date that takes three positive integer scalar inputs year, month, day. If these three represent a valid date, return a logical true, otherwise false. The name of the output argument is valid. If any of the inputs is not a positive integer scalar, return false as well. Note that every year that is exactly divisible by 4 is a leap year, except for years that are exactly divisible by 100. However, years that are exactly divisible by 400 are also leap years. For example, the year 1900 was not leap year, but the year 2000 was. Note that your solution must not contain any of the date related built-in MATLAB functions.
So ive seen other peoples code and ive been trying to get it on my own but to no luck fails all test but non-scalar and random non-leap years
function [valid] = valid_date(year, month, day);
leap_year = false;
valid = true;
if nargin ~= 3
valid = false;
else
end
if isscalar(year) && isscalar(month) && isscalar(day)
%%if isinteger(year) && isinteger(month) && isinteger(day)
if (year>=0) && (13>month>0) && (32>day>0)
%%fix(year), fix(month), fix(day)
if month == 2 && day == 29
leap_year = true;
elseif rem(year,400) == 0
leap_year = true;
elseif rem(year,4) == 0 && rem(year,100) ~= 0
leap_year = true;
else
leap_year = false;
end
if month ~= 1 || month ~= 3 || month ~= 5 || month ~= 7 || month ~= 9 month ~= 12 && day == 31
valid = false;
elseif month == 2 && day > 29
valid = false;
end
else
valid = false;
end
else
valid = false;
end if statement MATLAB Answers — New Questions
MATLAB coder-Check for Run-Time Issues,the output of test file is totally wrong compared with the original MATLAB code output
Use MATLAB coder to convert MATLAB code into C code suitable for Xilinx ARM development. However, when the conversion process proceeded to the MEX function check step, I found that the output of the test file using MEX was inconsistent with the output of the MATLAB code running directly. Here are the results running directly in MATLAB:
As the official tutorial shows, I split the code that needs to be translated into a data file (.mat), a separately encapsulated function file (.m), and a script that calls this function file (.m). The check was then performed in MATLAB coder, but the results were inconsistent
Here is the code in the test file to load the data and call the function. I can’t figure out why the results of the test file were incorrect when all the checks passed. Perhaps the converted code itself is not equivalent?
Note: The drawing of the final result is directly related to RY_final, and the built-in functions used by the converted function such as eig, sort, etc. should also support the conversion (otherwise it will not pass the check).
clear all
load(‘Data_02.mat’);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%R:core algorithm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[RNb_cub ,RYNb_cub, RY_final] = …
CoreFunc(PSub_mat, SDoa, var_n, M, N, J, K, Bin, Sample_vec, Time, Array, c, f_vec, EigVecNL_0);
……some compute and Plot the resultUse MATLAB coder to convert MATLAB code into C code suitable for Xilinx ARM development. However, when the conversion process proceeded to the MEX function check step, I found that the output of the test file using MEX was inconsistent with the output of the MATLAB code running directly. Here are the results running directly in MATLAB:
As the official tutorial shows, I split the code that needs to be translated into a data file (.mat), a separately encapsulated function file (.m), and a script that calls this function file (.m). The check was then performed in MATLAB coder, but the results were inconsistent
Here is the code in the test file to load the data and call the function. I can’t figure out why the results of the test file were incorrect when all the checks passed. Perhaps the converted code itself is not equivalent?
Note: The drawing of the final result is directly related to RY_final, and the built-in functions used by the converted function such as eig, sort, etc. should also support the conversion (otherwise it will not pass the check).
clear all
load(‘Data_02.mat’);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%R:core algorithm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[RNb_cub ,RYNb_cub, RY_final] = …
CoreFunc(PSub_mat, SDoa, var_n, M, N, J, K, Bin, Sample_vec, Time, Array, c, f_vec, EigVecNL_0);
……some compute and Plot the result Use MATLAB coder to convert MATLAB code into C code suitable for Xilinx ARM development. However, when the conversion process proceeded to the MEX function check step, I found that the output of the test file using MEX was inconsistent with the output of the MATLAB code running directly. Here are the results running directly in MATLAB:
As the official tutorial shows, I split the code that needs to be translated into a data file (.mat), a separately encapsulated function file (.m), and a script that calls this function file (.m). The check was then performed in MATLAB coder, but the results were inconsistent
Here is the code in the test file to load the data and call the function. I can’t figure out why the results of the test file were incorrect when all the checks passed. Perhaps the converted code itself is not equivalent?
Note: The drawing of the final result is directly related to RY_final, and the built-in functions used by the converted function such as eig, sort, etc. should also support the conversion (otherwise it will not pass the check).
clear all
load(‘Data_02.mat’);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%R:core algorithm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[RNb_cub ,RYNb_cub, RY_final] = …
CoreFunc(PSub_mat, SDoa, var_n, M, N, J, K, Bin, Sample_vec, Time, Array, c, f_vec, EigVecNL_0);
……some compute and Plot the result code generation, c convert MATLAB Answers — New Questions
Create “n” non-lineal equations in a loop and solved by Fsolve
Hi, guys…. I’ve been trying to create euqaitons to solve a non-lineal system in a loop. But, the number of functions to be created depends on the user (2<n<24)…. Turbine seal gas leak though labyrinth.
For example, when n=5 the loop should create 5 functions with 5 unknown variables (x1, x2, x3, x4, x5) and then, the system is solved by fsolve.
Here is my script:
All below variables are known:
n=;
pi=;
p0=;
pn=;
Ag=;
k1=;
k2=;
k3=;
k4=;
The equations:
—————————————————-
F(1)= (k1/p0^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((p0/x(i))^k4-1)+2*((p0/x(1))^k4-1)^2))^2-(x(i)/p0)^k2+(x(i)/p0)^k3];%…………. 1st equation
F(n)= [k1/(x(n-1))^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((x(n-1)/pn)^k4-1)+2*((x(n-)/pn)^k4-1)^2))^2-(pn/x(n-1))^k2+(pn/x(n-1))^k3]; %…………. “n” equation
%…………. for remained equations
For i=2:n-1
F(i) = (k1/(x(i))^2)*(x(n)*(1/(pi*Ag))*(pi+2-*((x(i)/x(i+1))^k4-1)+2*((x(i)/x(i+1))^k4-1)^2))^2- (x(i+1)/x(i))^k2+(x(i+1)/x(i))^k3;
End
————–
factor=(p0-pn)/n;
for i=1:(n-1)
x0(i)=p0-factor*i;
end
x0(n)=0;
——————-
options=optimoptions(‘fsolve’,’Display’,’iter’);
[x11,fval]=fsolve(F,x0,options)
Any help will be appreciated guys
Thanks in advance.Hi, guys…. I’ve been trying to create euqaitons to solve a non-lineal system in a loop. But, the number of functions to be created depends on the user (2<n<24)…. Turbine seal gas leak though labyrinth.
For example, when n=5 the loop should create 5 functions with 5 unknown variables (x1, x2, x3, x4, x5) and then, the system is solved by fsolve.
Here is my script:
All below variables are known:
n=;
pi=;
p0=;
pn=;
Ag=;
k1=;
k2=;
k3=;
k4=;
The equations:
—————————————————-
F(1)= (k1/p0^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((p0/x(i))^k4-1)+2*((p0/x(1))^k4-1)^2))^2-(x(i)/p0)^k2+(x(i)/p0)^k3];%…………. 1st equation
F(n)= [k1/(x(n-1))^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((x(n-1)/pn)^k4-1)+2*((x(n-)/pn)^k4-1)^2))^2-(pn/x(n-1))^k2+(pn/x(n-1))^k3]; %…………. “n” equation
%…………. for remained equations
For i=2:n-1
F(i) = (k1/(x(i))^2)*(x(n)*(1/(pi*Ag))*(pi+2-*((x(i)/x(i+1))^k4-1)+2*((x(i)/x(i+1))^k4-1)^2))^2- (x(i+1)/x(i))^k2+(x(i+1)/x(i))^k3;
End
————–
factor=(p0-pn)/n;
for i=1:(n-1)
x0(i)=p0-factor*i;
end
x0(n)=0;
——————-
options=optimoptions(‘fsolve’,’Display’,’iter’);
[x11,fval]=fsolve(F,x0,options)
Any help will be appreciated guys
Thanks in advance. Hi, guys…. I’ve been trying to create euqaitons to solve a non-lineal system in a loop. But, the number of functions to be created depends on the user (2<n<24)…. Turbine seal gas leak though labyrinth.
For example, when n=5 the loop should create 5 functions with 5 unknown variables (x1, x2, x3, x4, x5) and then, the system is solved by fsolve.
Here is my script:
All below variables are known:
n=;
pi=;
p0=;
pn=;
Ag=;
k1=;
k2=;
k3=;
k4=;
The equations:
—————————————————-
F(1)= (k1/p0^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((p0/x(i))^k4-1)+2*((p0/x(1))^k4-1)^2))^2-(x(i)/p0)^k2+(x(i)/p0)^k3];%…………. 1st equation
F(n)= [k1/(x(n-1))^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((x(n-1)/pn)^k4-1)+2*((x(n-)/pn)^k4-1)^2))^2-(pn/x(n-1))^k2+(pn/x(n-1))^k3]; %…………. “n” equation
%…………. for remained equations
For i=2:n-1
F(i) = (k1/(x(i))^2)*(x(n)*(1/(pi*Ag))*(pi+2-*((x(i)/x(i+1))^k4-1)+2*((x(i)/x(i+1))^k4-1)^2))^2- (x(i+1)/x(i))^k2+(x(i+1)/x(i))^k3;
End
————–
factor=(p0-pn)/n;
for i=1:(n-1)
x0(i)=p0-factor*i;
end
x0(n)=0;
——————-
options=optimoptions(‘fsolve’,’Display’,’iter’);
[x11,fval]=fsolve(F,x0,options)
Any help will be appreciated guys
Thanks in advance. fsolve, loop, nonlinear, functions MATLAB Answers — New Questions
No InputFormat ‘YYMMDD’ found for datetime
Is there a way to transform ‘240331’ into ’31 March 2024′ ?
The following does not work:
datetime(‘240331′,InputFormat,’YYMMDD’)Is there a way to transform ‘240331’ into ’31 March 2024′ ?
The following does not work:
datetime(‘240331′,InputFormat,’YYMMDD’) Is there a way to transform ‘240331’ into ’31 March 2024′ ?
The following does not work:
datetime(‘240331′,InputFormat,’YYMMDD’) datetime, inputformat MATLAB Answers — New Questions
where I can find mblibv1 library and install in my simulink?
I tried to simulate the cartpole simulation with simulink but I received the next message: Failed to load library ‘mblibv1’
How can I solve this problem? Where can I find it and install it?
Please suggestions. Many thanks in advance.I tried to simulate the cartpole simulation with simulink but I received the next message: Failed to load library ‘mblibv1’
How can I solve this problem? Where can I find it and install it?
Please suggestions. Many thanks in advance. I tried to simulate the cartpole simulation with simulink but I received the next message: Failed to load library ‘mblibv1’
How can I solve this problem? Where can I find it and install it?
Please suggestions. Many thanks in advance. failed to load library ‘mblibv1’, install ‘mblibv1’ library MATLAB Answers — New Questions