Tag Archives: matlab
How to get visualization of HOGfeatures
I used following code to extract HOG feature from an image in gui
if true
[HogFeature, visualization]= extractHOGFeatures(filepath,1);
axes(handles.axes3);
plot(visualization);
end
where filepath is my image, but when I start that part of code I get error "Error using extractHOGFeatures
Expected POINTS to be of size Mx2 when it is actually size 1×1."
What´s wrong?I used following code to extract HOG feature from an image in gui
if true
[HogFeature, visualization]= extractHOGFeatures(filepath,1);
axes(handles.axes3);
plot(visualization);
end
where filepath is my image, but when I start that part of code I get error "Error using extractHOGFeatures
Expected POINTS to be of size Mx2 when it is actually size 1×1."
What´s wrong? I used following code to extract HOG feature from an image in gui
if true
[HogFeature, visualization]= extractHOGFeatures(filepath,1);
axes(handles.axes3);
plot(visualization);
end
where filepath is my image, but when I start that part of code I get error "Error using extractHOGFeatures
Expected POINTS to be of size Mx2 when it is actually size 1×1."
What´s wrong? gui, extracthogfeatures MATLAB Answers — New Questions
taking difference of 2 surf figures of different sizes
One is to compare two solutions and study the error by taking their difference. The two solutions are two surf figures generated by surf(x1,y1,z1) and surf(x2,y2,z2) but x1 and x2 are different in size and so are y1, y2, z1, z2. One can think of this as two solutions z1, z2 obtained on 2 meshes. Is there a smart way of taking z1-z2 and surf’ing it?One is to compare two solutions and study the error by taking their difference. The two solutions are two surf figures generated by surf(x1,y1,z1) and surf(x2,y2,z2) but x1 and x2 are different in size and so are y1, y2, z1, z2. One can think of this as two solutions z1, z2 obtained on 2 meshes. Is there a smart way of taking z1-z2 and surf’ing it? One is to compare two solutions and study the error by taking their difference. The two solutions are two surf figures generated by surf(x1,y1,z1) and surf(x2,y2,z2) but x1 and x2 are different in size and so are y1, y2, z1, z2. One can think of this as two solutions z1, z2 obtained on 2 meshes. Is there a smart way of taking z1-z2 and surf’ing it? surf MATLAB Answers — New Questions
Fit a linear equation to obtain coefficients (constants)
Hi, I have a linear equation P = a + bM + c(Y-1) + d(M(Y-1)) where a, b, c and d are coefficients (constants). P, Y and M are known properties. Specifically, there are multiple P values, each with their corresponding Y and M values. How do I use matlab or excel to fit the data to the equation above to obatin the a, b, c & d coefficients? Please see image below. So each P value has 2 Y values and 2 M values. Any ideas?Hi, I have a linear equation P = a + bM + c(Y-1) + d(M(Y-1)) where a, b, c and d are coefficients (constants). P, Y and M are known properties. Specifically, there are multiple P values, each with their corresponding Y and M values. How do I use matlab or excel to fit the data to the equation above to obatin the a, b, c & d coefficients? Please see image below. So each P value has 2 Y values and 2 M values. Any ideas? Hi, I have a linear equation P = a + bM + c(Y-1) + d(M(Y-1)) where a, b, c and d are coefficients (constants). P, Y and M are known properties. Specifically, there are multiple P values, each with their corresponding Y and M values. How do I use matlab or excel to fit the data to the equation above to obatin the a, b, c & d coefficients? Please see image below. So each P value has 2 Y values and 2 M values. Any ideas? linear fit, curve fitting MATLAB Answers — New Questions
Error flag for infeasibility in nonlinear mpc.
I am getting the error flag -2 for my nonlinear mpc design despite their being no constraints. If there is no constraints, how is there infeasibility? The only way I can get it to be feasible is to make the intial condition the exact same as the reference. If there is deviation the problem is infeasible
clear all
nx = 4;
ny = 2;
nu = 3;
nlobj = nlmpc(nx,ny,nu);
nlobj.Ts = 0.1;
nlobj.PredictionHorizon = 10;
nlobj.ControlHorizon = 10;
nlobj.Model.StateFcn = @mystateFunctionREDUCED;
nlobj.Model.IsContinuousTime = true;
nlobj.Model.NumberOfParameters = 5;
rho = 0.1;
l = 1/2*1*rho^2;
%T = params(3);
g = 9.81;
J = 0.015;
m = 2;
nlobj.Model.OutputFcn = @OutputFcn
;
x0 = [1;0;pi/8;0];
mv = [m*g+1; 0; 0];
lastMV = mv;
%validateFcns(nlobj, x0, u0, [], {rho,l,g,J,m});
nloptions = nlmpcmoveopt;
nloptions.Parameters = {rho,l,g,J,m};
Duration = 1;
Ts = 0.01;
xHistory = x0′;
yref = [1;pi/9];
%nlobj.Weights.OutputVariables = [3 3];
%nlobj.Weights.ManipulatedVariablesRate = 0.1;
% nlobj.States(1).Min = 0;
% nlobj.States(1).Max = 20;
% nlobj.States(3).Min = 0;
% nlobj.States(3).Max = pi;
%nlobj.Optimization.CustomIneqConFcn = "myIneqConFunctionreduced";
nlobj.Weights.ManipulatedVariablesRate = [0 0 0];
nlobj.Weights.OutputVariables = [1 1];
%nlobj.Weights.ECR = 0;
Tarray = [];
Uarray = [];
for k = 1:(Duration/Ts)
xk = xHistory(k,:);
% Compute optimal control moves
[mv,nloptions,info] = nlmpcmove(nlobj,xk,lastMV,yref’,[],nloptions);
info
%disp(mv)
% Implement first optimal control move
ODEFUN = @(t,xk) statefcn(xk,mv);
[TOUT,XOUT] = ode45(ODEFUN,[0 Ts], xHistory(k,:)’);
x0 = mystateFunctionREDUCED(x0,mv,rho,l,g,J,m)*Ts+x0;
uHistory(k+1,:) = mv’;
lastMV = mv;
%[t,y] = ode15s(@mystateFunction,[0 Ts],[2 0]);
%T = (m*x0(1)*x0(4)^2-m*g*sin(x0(3))+mv(1)*sin(x0(3)+x0(5))-m*rho/l*mv(3))/(1+m*rho^2/l);
%Tarray = [Tarray T];
Uarray = [Uarray mv];
xHistory(k+1,:) = XOUT(end,:);
%opt.Slack0
%T
%par = m*x0(1).*x0(4).^2-m*g*sin(x0(3))
% Save plant states
%xHistory = [xHistory x0];
end
function z = mystateFunctionREDUCED(x,u,rho,l,g,J,m)
z = zeros(4,1);
% rho = params(1);
% l = params(2);
% %T = params(3);
% g = params(3);
% J = params(4);
% m = params(5);
z(1) = x(2);
z(2) = (rho/l*u(3)+(rho^2/l)*(m*x(1)*x(4)^2-m*g*sin(x(3)+u(1)*sin(x(3)+u(2)))))/(1+rho^2*m/l);
z(3) = x(4);
z(4) = (-1/x(1))*(2*x(2)*x(4)+g*cos(x(3)))+1/(m*x(1))*u(1)*cos(x(3)+u(2));
end
function y = OutputFcn(x,u,rho,l,g,J,m)
y = zeros(2,1);
y(1) = x(1);
y(2) = x(3);
end
function f = statefcn(in1,in2)
%QuadrotorStateFcn
% F = QuadrotorStateFcn(IN1,IN2)
% This function was generated by the Symbolic Math Toolbox version 24.1.
% 09-Jan-2025 19:28:44
rho = 0.1;
l = 1/2*1*rho^2;
%T = params(3);
g = 9.81;
J = 0.015;
m = 2;
x = in1;
u = in2;
z(1) = x(2);
z(2) = (rho/l*u(3)+(rho^2/l)*(m*x(1)*x(4)^2-m*g*sin(x(3)+u(1)*sin(x(3)+u(2)))))/(1+rho^2*m/l);
z(3) = x(4);
z(4) = (-1/x(1))*(2*x(2)*x(4)+g*cos(x(3)))+1/(m*x(1))*u(1)*cos(x(3)+u(2));
f = [z(1);z(2);z(3);z(4)];
endI am getting the error flag -2 for my nonlinear mpc design despite their being no constraints. If there is no constraints, how is there infeasibility? The only way I can get it to be feasible is to make the intial condition the exact same as the reference. If there is deviation the problem is infeasible
clear all
nx = 4;
ny = 2;
nu = 3;
nlobj = nlmpc(nx,ny,nu);
nlobj.Ts = 0.1;
nlobj.PredictionHorizon = 10;
nlobj.ControlHorizon = 10;
nlobj.Model.StateFcn = @mystateFunctionREDUCED;
nlobj.Model.IsContinuousTime = true;
nlobj.Model.NumberOfParameters = 5;
rho = 0.1;
l = 1/2*1*rho^2;
%T = params(3);
g = 9.81;
J = 0.015;
m = 2;
nlobj.Model.OutputFcn = @OutputFcn
;
x0 = [1;0;pi/8;0];
mv = [m*g+1; 0; 0];
lastMV = mv;
%validateFcns(nlobj, x0, u0, [], {rho,l,g,J,m});
nloptions = nlmpcmoveopt;
nloptions.Parameters = {rho,l,g,J,m};
Duration = 1;
Ts = 0.01;
xHistory = x0′;
yref = [1;pi/9];
%nlobj.Weights.OutputVariables = [3 3];
%nlobj.Weights.ManipulatedVariablesRate = 0.1;
% nlobj.States(1).Min = 0;
% nlobj.States(1).Max = 20;
% nlobj.States(3).Min = 0;
% nlobj.States(3).Max = pi;
%nlobj.Optimization.CustomIneqConFcn = "myIneqConFunctionreduced";
nlobj.Weights.ManipulatedVariablesRate = [0 0 0];
nlobj.Weights.OutputVariables = [1 1];
%nlobj.Weights.ECR = 0;
Tarray = [];
Uarray = [];
for k = 1:(Duration/Ts)
xk = xHistory(k,:);
% Compute optimal control moves
[mv,nloptions,info] = nlmpcmove(nlobj,xk,lastMV,yref’,[],nloptions);
info
%disp(mv)
% Implement first optimal control move
ODEFUN = @(t,xk) statefcn(xk,mv);
[TOUT,XOUT] = ode45(ODEFUN,[0 Ts], xHistory(k,:)’);
x0 = mystateFunctionREDUCED(x0,mv,rho,l,g,J,m)*Ts+x0;
uHistory(k+1,:) = mv’;
lastMV = mv;
%[t,y] = ode15s(@mystateFunction,[0 Ts],[2 0]);
%T = (m*x0(1)*x0(4)^2-m*g*sin(x0(3))+mv(1)*sin(x0(3)+x0(5))-m*rho/l*mv(3))/(1+m*rho^2/l);
%Tarray = [Tarray T];
Uarray = [Uarray mv];
xHistory(k+1,:) = XOUT(end,:);
%opt.Slack0
%T
%par = m*x0(1).*x0(4).^2-m*g*sin(x0(3))
% Save plant states
%xHistory = [xHistory x0];
end
function z = mystateFunctionREDUCED(x,u,rho,l,g,J,m)
z = zeros(4,1);
% rho = params(1);
% l = params(2);
% %T = params(3);
% g = params(3);
% J = params(4);
% m = params(5);
z(1) = x(2);
z(2) = (rho/l*u(3)+(rho^2/l)*(m*x(1)*x(4)^2-m*g*sin(x(3)+u(1)*sin(x(3)+u(2)))))/(1+rho^2*m/l);
z(3) = x(4);
z(4) = (-1/x(1))*(2*x(2)*x(4)+g*cos(x(3)))+1/(m*x(1))*u(1)*cos(x(3)+u(2));
end
function y = OutputFcn(x,u,rho,l,g,J,m)
y = zeros(2,1);
y(1) = x(1);
y(2) = x(3);
end
function f = statefcn(in1,in2)
%QuadrotorStateFcn
% F = QuadrotorStateFcn(IN1,IN2)
% This function was generated by the Symbolic Math Toolbox version 24.1.
% 09-Jan-2025 19:28:44
rho = 0.1;
l = 1/2*1*rho^2;
%T = params(3);
g = 9.81;
J = 0.015;
m = 2;
x = in1;
u = in2;
z(1) = x(2);
z(2) = (rho/l*u(3)+(rho^2/l)*(m*x(1)*x(4)^2-m*g*sin(x(3)+u(1)*sin(x(3)+u(2)))))/(1+rho^2*m/l);
z(3) = x(4);
z(4) = (-1/x(1))*(2*x(2)*x(4)+g*cos(x(3)))+1/(m*x(1))*u(1)*cos(x(3)+u(2));
f = [z(1);z(2);z(3);z(4)];
end I am getting the error flag -2 for my nonlinear mpc design despite their being no constraints. If there is no constraints, how is there infeasibility? The only way I can get it to be feasible is to make the intial condition the exact same as the reference. If there is deviation the problem is infeasible
clear all
nx = 4;
ny = 2;
nu = 3;
nlobj = nlmpc(nx,ny,nu);
nlobj.Ts = 0.1;
nlobj.PredictionHorizon = 10;
nlobj.ControlHorizon = 10;
nlobj.Model.StateFcn = @mystateFunctionREDUCED;
nlobj.Model.IsContinuousTime = true;
nlobj.Model.NumberOfParameters = 5;
rho = 0.1;
l = 1/2*1*rho^2;
%T = params(3);
g = 9.81;
J = 0.015;
m = 2;
nlobj.Model.OutputFcn = @OutputFcn
;
x0 = [1;0;pi/8;0];
mv = [m*g+1; 0; 0];
lastMV = mv;
%validateFcns(nlobj, x0, u0, [], {rho,l,g,J,m});
nloptions = nlmpcmoveopt;
nloptions.Parameters = {rho,l,g,J,m};
Duration = 1;
Ts = 0.01;
xHistory = x0′;
yref = [1;pi/9];
%nlobj.Weights.OutputVariables = [3 3];
%nlobj.Weights.ManipulatedVariablesRate = 0.1;
% nlobj.States(1).Min = 0;
% nlobj.States(1).Max = 20;
% nlobj.States(3).Min = 0;
% nlobj.States(3).Max = pi;
%nlobj.Optimization.CustomIneqConFcn = "myIneqConFunctionreduced";
nlobj.Weights.ManipulatedVariablesRate = [0 0 0];
nlobj.Weights.OutputVariables = [1 1];
%nlobj.Weights.ECR = 0;
Tarray = [];
Uarray = [];
for k = 1:(Duration/Ts)
xk = xHistory(k,:);
% Compute optimal control moves
[mv,nloptions,info] = nlmpcmove(nlobj,xk,lastMV,yref’,[],nloptions);
info
%disp(mv)
% Implement first optimal control move
ODEFUN = @(t,xk) statefcn(xk,mv);
[TOUT,XOUT] = ode45(ODEFUN,[0 Ts], xHistory(k,:)’);
x0 = mystateFunctionREDUCED(x0,mv,rho,l,g,J,m)*Ts+x0;
uHistory(k+1,:) = mv’;
lastMV = mv;
%[t,y] = ode15s(@mystateFunction,[0 Ts],[2 0]);
%T = (m*x0(1)*x0(4)^2-m*g*sin(x0(3))+mv(1)*sin(x0(3)+x0(5))-m*rho/l*mv(3))/(1+m*rho^2/l);
%Tarray = [Tarray T];
Uarray = [Uarray mv];
xHistory(k+1,:) = XOUT(end,:);
%opt.Slack0
%T
%par = m*x0(1).*x0(4).^2-m*g*sin(x0(3))
% Save plant states
%xHistory = [xHistory x0];
end
function z = mystateFunctionREDUCED(x,u,rho,l,g,J,m)
z = zeros(4,1);
% rho = params(1);
% l = params(2);
% %T = params(3);
% g = params(3);
% J = params(4);
% m = params(5);
z(1) = x(2);
z(2) = (rho/l*u(3)+(rho^2/l)*(m*x(1)*x(4)^2-m*g*sin(x(3)+u(1)*sin(x(3)+u(2)))))/(1+rho^2*m/l);
z(3) = x(4);
z(4) = (-1/x(1))*(2*x(2)*x(4)+g*cos(x(3)))+1/(m*x(1))*u(1)*cos(x(3)+u(2));
end
function y = OutputFcn(x,u,rho,l,g,J,m)
y = zeros(2,1);
y(1) = x(1);
y(2) = x(3);
end
function f = statefcn(in1,in2)
%QuadrotorStateFcn
% F = QuadrotorStateFcn(IN1,IN2)
% This function was generated by the Symbolic Math Toolbox version 24.1.
% 09-Jan-2025 19:28:44
rho = 0.1;
l = 1/2*1*rho^2;
%T = params(3);
g = 9.81;
J = 0.015;
m = 2;
x = in1;
u = in2;
z(1) = x(2);
z(2) = (rho/l*u(3)+(rho^2/l)*(m*x(1)*x(4)^2-m*g*sin(x(3)+u(1)*sin(x(3)+u(2)))))/(1+rho^2*m/l);
z(3) = x(4);
z(4) = (-1/x(1))*(2*x(2)*x(4)+g*cos(x(3)))+1/(m*x(1))*u(1)*cos(x(3)+u(2));
f = [z(1);z(2);z(3);z(4)];
end control, mpc MATLAB Answers — New Questions
tuning paramters in referenced model whithin a Simulink Real-Time model
Previous to R2020b, we can tune the parameter inside the model reference by the command such as:
tPar_a = getparamid(tg, ‘ModelReference1/subsys1/a’,’Value’);
setparam(tg,tPar_a,1);
After I upgrated to R2024a, the above commands are not availble anymore. I can get and set parameters of the top model, but I can not change parameter values insie the model reference and all the parameters in the model reference are not showing in SLRT_explorer neither. Is there anyway to get the parameter values in the model reference and tune them during simulink realtime simulation?Previous to R2020b, we can tune the parameter inside the model reference by the command such as:
tPar_a = getparamid(tg, ‘ModelReference1/subsys1/a’,’Value’);
setparam(tg,tPar_a,1);
After I upgrated to R2024a, the above commands are not availble anymore. I can get and set parameters of the top model, but I can not change parameter values insie the model reference and all the parameters in the model reference are not showing in SLRT_explorer neither. Is there anyway to get the parameter values in the model reference and tune them during simulink realtime simulation? Previous to R2020b, we can tune the parameter inside the model reference by the command such as:
tPar_a = getparamid(tg, ‘ModelReference1/subsys1/a’,’Value’);
setparam(tg,tPar_a,1);
After I upgrated to R2024a, the above commands are not availble anymore. I can get and set parameters of the top model, but I can not change parameter values insie the model reference and all the parameters in the model reference are not showing in SLRT_explorer neither. Is there anyway to get the parameter values in the model reference and tune them during simulink realtime simulation? tuning modelreference parameter MATLAB Answers — New Questions
Why is the Symmetric circle grid not available as an option in the camera calibrator?
Hi all,
I am trying to use the Stereo Camera Calibrator app in MATLAB 2024a, specifically with the ‘Symmetric circle grid’ pattern. But when I go to select this option, it is not available in the drop down menu (See below)
I was also using this app in late 2024 using 2023b and 2024a and the option was available to use but it has since disappeared. I have also tried to access it on 3 different devices and 5 different MATLAB releases (2016b, 2023a, 2023b, 2024a and 2024b) but it seems to have disappeared from all of them. Has it been removed as an option recently? I didn’t find any indication of this in release notes or bug reports.
Any advice on how to fix this problem would be very welcome.
Thank you!Hi all,
I am trying to use the Stereo Camera Calibrator app in MATLAB 2024a, specifically with the ‘Symmetric circle grid’ pattern. But when I go to select this option, it is not available in the drop down menu (See below)
I was also using this app in late 2024 using 2023b and 2024a and the option was available to use but it has since disappeared. I have also tried to access it on 3 different devices and 5 different MATLAB releases (2016b, 2023a, 2023b, 2024a and 2024b) but it seems to have disappeared from all of them. Has it been removed as an option recently? I didn’t find any indication of this in release notes or bug reports.
Any advice on how to fix this problem would be very welcome.
Thank you! Hi all,
I am trying to use the Stereo Camera Calibrator app in MATLAB 2024a, specifically with the ‘Symmetric circle grid’ pattern. But when I go to select this option, it is not available in the drop down menu (See below)
I was also using this app in late 2024 using 2023b and 2024a and the option was available to use but it has since disappeared. I have also tried to access it on 3 different devices and 5 different MATLAB releases (2016b, 2023a, 2023b, 2024a and 2024b) but it seems to have disappeared from all of them. Has it been removed as an option recently? I didn’t find any indication of this in release notes or bug reports.
Any advice on how to fix this problem would be very welcome.
Thank you! computer vision, camera-calibration MATLAB Answers — New Questions
What is the proper syntax used to enter a vertical intercept?
Im having issues entering the y intercept of a graph. It is clearly the point (0,-3). I have tried -3, (-3), y=-3, (0,-3) and all of them have an error code of . (:span class="AMHnotice":)Invalid notation. (:/span:)Im having issues entering the y intercept of a graph. It is clearly the point (0,-3). I have tried -3, (-3), y=-3, (0,-3) and all of them have an error code of . (:span class="AMHnotice":)Invalid notation. (:/span:) Im having issues entering the y intercept of a graph. It is clearly the point (0,-3). I have tried -3, (-3), y=-3, (0,-3) and all of them have an error code of . (:span class="AMHnotice":)Invalid notation. (:/span:) syntax error, intercepts MATLAB Answers — New Questions
vpa(4503599627370491.5)
vpa(4503599627370491.5)
produces
4503599627370496.0
in 2017b.
Why?
Further,
sym(4503599627370491.5)-sym(4503599627370496)
produces
0.vpa(4503599627370491.5)
produces
4503599627370496.0
in 2017b.
Why?
Further,
sym(4503599627370491.5)-sym(4503599627370496)
produces
0. vpa(4503599627370491.5)
produces
4503599627370496.0
in 2017b.
Why?
Further,
sym(4503599627370491.5)-sym(4503599627370496)
produces
0. vpa, sym MATLAB Answers — New Questions
Extract individual curve from a multiple curve plot
I have plottedthe attached data using
figure; scatter(data(:,1),data(:,2)); It gives me plot as shown below
As can be seen from the figure that we have 11 curves in this plot. How can I trace each curve and get (X,Y) value and so that I have X and Y values for all 11 curves?I have plottedthe attached data using
figure; scatter(data(:,1),data(:,2)); It gives me plot as shown below
As can be seen from the figure that we have 11 curves in this plot. How can I trace each curve and get (X,Y) value and so that I have X and Y values for all 11 curves? I have plottedthe attached data using
figure; scatter(data(:,1),data(:,2)); It gives me plot as shown below
As can be seen from the figure that we have 11 curves in this plot. How can I trace each curve and get (X,Y) value and so that I have X and Y values for all 11 curves? curve tracing, ploting, image processing, data analysis, clustering, plot MATLAB Answers — New Questions
How can I access files in my Microsoft OneDrive using MATLAB Online?
I am trying to access files in my Microsoft OneDrive while using MATLAB Online. How do I enable MATLAB Online to access Microsoft OneDrive?I am trying to access files in my Microsoft OneDrive while using MATLAB Online. How do I enable MATLAB Online to access Microsoft OneDrive? I am trying to access files in my Microsoft OneDrive while using MATLAB Online. How do I enable MATLAB Online to access Microsoft OneDrive? microsoft, onedrive, matlab-online MATLAB Answers — New Questions
Calculate when to detach a small rocket
Hello,
I have a big Matlab asignment, which is due soon. The project is devided into several parts, a,b, c and d. Problem a is to calculate maximum height if we only have one rocket. Problem b is to calculate where this rocket will launch. I have solved these using Runge kutta method. I am currently stuck on problem c, which is calculating when to release a seccond rocket to obtain maximal distance.
Is anyone able to help with this? Any help is greatly appriciated.
Files in link, (sadly wasnt able to upload directly) Matlab_filesHello,
I have a big Matlab asignment, which is due soon. The project is devided into several parts, a,b, c and d. Problem a is to calculate maximum height if we only have one rocket. Problem b is to calculate where this rocket will launch. I have solved these using Runge kutta method. I am currently stuck on problem c, which is calculating when to release a seccond rocket to obtain maximal distance.
Is anyone able to help with this? Any help is greatly appriciated.
Files in link, (sadly wasnt able to upload directly) Matlab_files Hello,
I have a big Matlab asignment, which is due soon. The project is devided into several parts, a,b, c and d. Problem a is to calculate maximum height if we only have one rocket. Problem b is to calculate where this rocket will launch. I have solved these using Runge kutta method. I am currently stuck on problem c, which is calculating when to release a seccond rocket to obtain maximal distance.
Is anyone able to help with this? Any help is greatly appriciated.
Files in link, (sadly wasnt able to upload directly) Matlab_files matlab, differential equations, trajectory MATLAB Answers — New Questions
How to Configure your Student Competition License
How to Configure your Student Competition LicenseHow to Configure your Student Competition License How to Configure your Student Competition License student, competition MATLAB Answers — New Questions
How can I filter a FFt signal to only show the main frequency?
I have the following code (a sample data file is attached).
load("sample_signal.mat");
whos
figure
subplot(2,1,1)
hold on; grid minor
plot(signals.signal_01.signal)
plot(signals.signal_02.signal)
plot(signals.signal_03.time, signals.signal_03.theta, ‘k’)
title("Signal");
subplot(2,1,2)
hold on; grid minor
fs = 1;
[freq, amplitude, phase] = generic_fft(signals.signal_01.signal, fs);
plot(freq, amplitude)
[freq, amplitude, phase] = generic_fft(signals.signal_02.signal, fs);
plot(freq, amplitude)
fs = 10;
[freq, amplitude, phase] = generic_fft(signals.signal_03.theta, fs);
plot(freq, amplitude, ‘k’)
xlim([0 0.5])
xlabel("$omega$ [rad/s]")
ylabel("fft")
title("FFT");
% fft function
function [freq, amplitude, phase] = generic_fft(signal, fs)
% Remove NaNs
signal = signal(~isnan(signal));
% Length of the signal
n = length(signal);
% Perform FFT
fft_values = fft(signal);
% Compute single-sided amplitude spectrum
amplitude = abs(fft_values / n); % Normalize by length
amplitude = amplitude(1:floor(n / 2) + 1); % Keep positive frequencies
amplitude(2:end-1) = 2 * amplitude(2:end-1);
% Compute single-sided phase spectrum
phase = angle(fft_values(1:floor(n / 2) + 1));
% Frequency vector
freq = (0:(n / 2)) * (fs / n);
end
Now, the signal plotted in black shows a clear, dominant frequency in the FFt, but the other two signals show additional "noise" (see, after 0.1 rad/s). Is it possible to maybe filter these out or only show the dominant frequency?
The code is rough and the data structure is also not ideal (I saved the data mid-simulation for this question 🙂 ). Also, any tips to improve the fft function is also very appreciated. TIA!I have the following code (a sample data file is attached).
load("sample_signal.mat");
whos
figure
subplot(2,1,1)
hold on; grid minor
plot(signals.signal_01.signal)
plot(signals.signal_02.signal)
plot(signals.signal_03.time, signals.signal_03.theta, ‘k’)
title("Signal");
subplot(2,1,2)
hold on; grid minor
fs = 1;
[freq, amplitude, phase] = generic_fft(signals.signal_01.signal, fs);
plot(freq, amplitude)
[freq, amplitude, phase] = generic_fft(signals.signal_02.signal, fs);
plot(freq, amplitude)
fs = 10;
[freq, amplitude, phase] = generic_fft(signals.signal_03.theta, fs);
plot(freq, amplitude, ‘k’)
xlim([0 0.5])
xlabel("$omega$ [rad/s]")
ylabel("fft")
title("FFT");
% fft function
function [freq, amplitude, phase] = generic_fft(signal, fs)
% Remove NaNs
signal = signal(~isnan(signal));
% Length of the signal
n = length(signal);
% Perform FFT
fft_values = fft(signal);
% Compute single-sided amplitude spectrum
amplitude = abs(fft_values / n); % Normalize by length
amplitude = amplitude(1:floor(n / 2) + 1); % Keep positive frequencies
amplitude(2:end-1) = 2 * amplitude(2:end-1);
% Compute single-sided phase spectrum
phase = angle(fft_values(1:floor(n / 2) + 1));
% Frequency vector
freq = (0:(n / 2)) * (fs / n);
end
Now, the signal plotted in black shows a clear, dominant frequency in the FFt, but the other two signals show additional "noise" (see, after 0.1 rad/s). Is it possible to maybe filter these out or only show the dominant frequency?
The code is rough and the data structure is also not ideal (I saved the data mid-simulation for this question 🙂 ). Also, any tips to improve the fft function is also very appreciated. TIA! I have the following code (a sample data file is attached).
load("sample_signal.mat");
whos
figure
subplot(2,1,1)
hold on; grid minor
plot(signals.signal_01.signal)
plot(signals.signal_02.signal)
plot(signals.signal_03.time, signals.signal_03.theta, ‘k’)
title("Signal");
subplot(2,1,2)
hold on; grid minor
fs = 1;
[freq, amplitude, phase] = generic_fft(signals.signal_01.signal, fs);
plot(freq, amplitude)
[freq, amplitude, phase] = generic_fft(signals.signal_02.signal, fs);
plot(freq, amplitude)
fs = 10;
[freq, amplitude, phase] = generic_fft(signals.signal_03.theta, fs);
plot(freq, amplitude, ‘k’)
xlim([0 0.5])
xlabel("$omega$ [rad/s]")
ylabel("fft")
title("FFT");
% fft function
function [freq, amplitude, phase] = generic_fft(signal, fs)
% Remove NaNs
signal = signal(~isnan(signal));
% Length of the signal
n = length(signal);
% Perform FFT
fft_values = fft(signal);
% Compute single-sided amplitude spectrum
amplitude = abs(fft_values / n); % Normalize by length
amplitude = amplitude(1:floor(n / 2) + 1); % Keep positive frequencies
amplitude(2:end-1) = 2 * amplitude(2:end-1);
% Compute single-sided phase spectrum
phase = angle(fft_values(1:floor(n / 2) + 1));
% Frequency vector
freq = (0:(n / 2)) * (fs / n);
end
Now, the signal plotted in black shows a clear, dominant frequency in the FFt, but the other two signals show additional "noise" (see, after 0.1 rad/s). Is it possible to maybe filter these out or only show the dominant frequency?
The code is rough and the data structure is also not ideal (I saved the data mid-simulation for this question 🙂 ). Also, any tips to improve the fft function is also very appreciated. TIA! fft, filter, plot MATLAB Answers — New Questions
Errors encountered when implementing the code of “Train Voice Activity Detection in Noise Model Using Deep Learning”
Hello,I encountered an error while running the example code from the MathWorks tutorial "Train Voice Activity Detection in Noise Model Using Deep Learning". I am using MATLAB Online and did not modify the original code.The error occurs at line 150 when calling the trainnet function:
noisyvadnet = trainnet(XTrain, TTrain, net, "mse", options);
The error message is:
Error using trainnet (line 54)
Execution failed during layer(s) "cnn2.norm1".
Caused by:
Arrays have incompatible sizes for this operation.
Error in deep.internal.recording.operations.TimesBroadcastOp/forward (line 31)
x = x .* y;
^
Error in .* (line 39)
zdata = matlab.lang.internal.move(xdata) .* matlab.lang.internal.move(ydata);
^
Error in audio.ai.vadnet.layers.layerNormalizationElementwiseLayer/predict (line 59)
Z = layer.Scale.*Xn + layer.Bias;
^
Error in nnet.layer.Layer/forward (line 129)
[varargout{1:layer.NumOutputs+layer.PrivateNumStates}] = predict( layer, varargin{:} );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since many functions related to this error are read-only, I cannot insert debugging code to investigate further.Could you please help me understand why this error occurs and how to resolve it?Thank you!Hello,I encountered an error while running the example code from the MathWorks tutorial "Train Voice Activity Detection in Noise Model Using Deep Learning". I am using MATLAB Online and did not modify the original code.The error occurs at line 150 when calling the trainnet function:
noisyvadnet = trainnet(XTrain, TTrain, net, "mse", options);
The error message is:
Error using trainnet (line 54)
Execution failed during layer(s) "cnn2.norm1".
Caused by:
Arrays have incompatible sizes for this operation.
Error in deep.internal.recording.operations.TimesBroadcastOp/forward (line 31)
x = x .* y;
^
Error in .* (line 39)
zdata = matlab.lang.internal.move(xdata) .* matlab.lang.internal.move(ydata);
^
Error in audio.ai.vadnet.layers.layerNormalizationElementwiseLayer/predict (line 59)
Z = layer.Scale.*Xn + layer.Bias;
^
Error in nnet.layer.Layer/forward (line 129)
[varargout{1:layer.NumOutputs+layer.PrivateNumStates}] = predict( layer, varargin{:} );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since many functions related to this error are read-only, I cannot insert debugging code to investigate further.Could you please help me understand why this error occurs and how to resolve it?Thank you! Hello,I encountered an error while running the example code from the MathWorks tutorial "Train Voice Activity Detection in Noise Model Using Deep Learning". I am using MATLAB Online and did not modify the original code.The error occurs at line 150 when calling the trainnet function:
noisyvadnet = trainnet(XTrain, TTrain, net, "mse", options);
The error message is:
Error using trainnet (line 54)
Execution failed during layer(s) "cnn2.norm1".
Caused by:
Arrays have incompatible sizes for this operation.
Error in deep.internal.recording.operations.TimesBroadcastOp/forward (line 31)
x = x .* y;
^
Error in .* (line 39)
zdata = matlab.lang.internal.move(xdata) .* matlab.lang.internal.move(ydata);
^
Error in audio.ai.vadnet.layers.layerNormalizationElementwiseLayer/predict (line 59)
Z = layer.Scale.*Xn + layer.Bias;
^
Error in nnet.layer.Layer/forward (line 129)
[varargout{1:layer.NumOutputs+layer.PrivateNumStates}] = predict( layer, varargin{:} );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since many functions related to this error are read-only, I cannot insert debugging code to investigate further.Could you please help me understand why this error occurs and how to resolve it?Thank you! incompatible sizes, tutorial code MATLAB Answers — New Questions
MINLP problem in MATLAB with both integer constraints and nonlinear equality constraints
Knowing that: “When there are integer constraints, ga and gamultiobj do not accept nonlinear equality constraints, only nonlinear inequality constraints.”, How do you solve MINLP problems of the following form in MATLAB?Knowing that: “When there are integer constraints, ga and gamultiobj do not accept nonlinear equality constraints, only nonlinear inequality constraints.”, How do you solve MINLP problems of the following form in MATLAB? Knowing that: “When there are integer constraints, ga and gamultiobj do not accept nonlinear equality constraints, only nonlinear inequality constraints.”, How do you solve MINLP problems of the following form in MATLAB? minlp MATLAB Answers — New Questions
Configuration of ROS Toolbox through CLI?
Hello everyone,
my main question is in the title. For reference, I want to create a docker container running matlab to generate some standalone ROS2 nodes. This works fine until I have to set the path to the Python-executable. It seems to be only possible through the GUI. Am I mistaken here and is there maybe a way to set the executable and create the venv via CLI commands?
Best regards,
SönkeHello everyone,
my main question is in the title. For reference, I want to create a docker container running matlab to generate some standalone ROS2 nodes. This works fine until I have to set the path to the Python-executable. It seems to be only possible through the GUI. Am I mistaken here and is there maybe a way to set the executable and create the venv via CLI commands?
Best regards,
Sönke Hello everyone,
my main question is in the title. For reference, I want to create a docker container running matlab to generate some standalone ROS2 nodes. This works fine until I have to set the path to the Python-executable. It seems to be only possible through the GUI. Am I mistaken here and is there maybe a way to set the executable and create the venv via CLI commands?
Best regards,
Sönke ros2, cli, container, docker MATLAB Answers — New Questions
Is it possible to export Tool-coupling FMU from Simulink model with compiled MEX S function? [r2019b]
hi, i try to export a FMU from Simulink model in which has a compiled MEX S function. I import the generated FMU to Simulink and it could not run successfully.
Is this only possible to export FMU with white box model?
Thanks in advance.hi, i try to export a FMU from Simulink model in which has a compiled MEX S function. I import the generated FMU to Simulink and it could not run successfully.
Is this only possible to export FMU with white box model?
Thanks in advance. hi, i try to export a FMU from Simulink model in which has a compiled MEX S function. I import the generated FMU to Simulink and it could not run successfully.
Is this only possible to export FMU with white box model?
Thanks in advance. fmu export MATLAB Answers — New Questions
Class Property Validation for the Contents of a Cell Array Property?
I’m writing a class that stores its data in the form of cell arrays, matching values to their units. An example property definition might look something like:
classdef myClass
properties (SetAccess = private)
prop1 (2, 2) cell = { 1000, "m" ; 1, "km" }
end
end
In the class definition, I’d like to use property validation to restrict the values in column 1 to valid distances, nonnegative for example, and column 2 to valid strings that define an actual unit type, "m"/"ft"/"in" for example. This is trivial for defined types, like ‘int16’ or ‘double’, but I’m wondering if anyone has accomplished this for columns/rows inside a cell array. The goal here is to store property value with its unit, while also restricting both to valid input. Is this possible given the cell type at property definition? Thanks!I’m writing a class that stores its data in the form of cell arrays, matching values to their units. An example property definition might look something like:
classdef myClass
properties (SetAccess = private)
prop1 (2, 2) cell = { 1000, "m" ; 1, "km" }
end
end
In the class definition, I’d like to use property validation to restrict the values in column 1 to valid distances, nonnegative for example, and column 2 to valid strings that define an actual unit type, "m"/"ft"/"in" for example. This is trivial for defined types, like ‘int16’ or ‘double’, but I’m wondering if anyone has accomplished this for columns/rows inside a cell array. The goal here is to store property value with its unit, while also restricting both to valid input. Is this possible given the cell type at property definition? Thanks! I’m writing a class that stores its data in the form of cell arrays, matching values to their units. An example property definition might look something like:
classdef myClass
properties (SetAccess = private)
prop1 (2, 2) cell = { 1000, "m" ; 1, "km" }
end
end
In the class definition, I’d like to use property validation to restrict the values in column 1 to valid distances, nonnegative for example, and column 2 to valid strings that define an actual unit type, "m"/"ft"/"in" for example. This is trivial for defined types, like ‘int16’ or ‘double’, but I’m wondering if anyone has accomplished this for columns/rows inside a cell array. The goal here is to store property value with its unit, while also restricting both to valid input. Is this possible given the cell type at property definition? Thanks! cell arrays, property validation MATLAB Answers — New Questions
Simulink Raspberry Code Generation Running Very Slow
I am trying to compile a simple gpio trigger signal that I created with Simulink and run it on the raspberry. But unfortunately, when I measure with an oscilloscope from the gpio pin, which should trigger 2khz, I see a 2hz measurement. I would appreciate if you can help with this. It is interesting that even *very simple models* have such problems. (Matlab2024a)I am trying to compile a simple gpio trigger signal that I created with Simulink and run it on the raspberry. But unfortunately, when I measure with an oscilloscope from the gpio pin, which should trigger 2khz, I see a 2hz measurement. I would appreciate if you can help with this. It is interesting that even *very simple models* have such problems. (Matlab2024a) I am trying to compile a simple gpio trigger signal that I created with Simulink and run it on the raspberry. But unfortunately, when I measure with an oscilloscope from the gpio pin, which should trigger 2khz, I see a 2hz measurement. I would appreciate if you can help with this. It is interesting that even *very simple models* have such problems. (Matlab2024a) simulink, code generation MATLAB Answers — New Questions
Simulink model deployed in Raspberry Pi is not running in Real-time
I have a simulink model for grid connected PV system. In that model Modbus Slave write blocks are used to store all the power system network measurements, so that these values can be read from other Modbus master device.
The model is successfully built and gets deployed on Raspi with out any errors. I could read the values from another modbus mater. However, the model is running very slowly, and it tooks minutes to reach to the state of 1 sec in simulation.
Please help me, How can I solve this issue.I have a simulink model for grid connected PV system. In that model Modbus Slave write blocks are used to store all the power system network measurements, so that these values can be read from other Modbus master device.
The model is successfully built and gets deployed on Raspi with out any errors. I could read the values from another modbus mater. However, the model is running very slowly, and it tooks minutes to reach to the state of 1 sec in simulation.
Please help me, How can I solve this issue. I have a simulink model for grid connected PV system. In that model Modbus Slave write blocks are used to store all the power system network measurements, so that these values can be read from other Modbus master device.
The model is successfully built and gets deployed on Raspi with out any errors. I could read the values from another modbus mater. However, the model is running very slowly, and it tooks minutes to reach to the state of 1 sec in simulation.
Please help me, How can I solve this issue. simulink interface with raspberry pi MATLAB Answers — New Questions