From Workspace Simulink dimension error
Mostra commenti meno recenti
Hi, I have a problem with the From Workspace block. I have 4 vars in the workspace of MATLAB and I need to export Simulink with that block. How I correct that error?
Risposte (1)
Ameer Hamza
il 2 Mag 2020
0 voti
These variables are constant. You can use the constant block to get their value in Simulink: https://www.mathworks.com/help/releases/R2020a/simulink/slref/constant.html and in the value field, write the name of the variable. The Simulink constant block is able to read the value from the base workspace.
18 Commenti
Juan Sebastian Corredor Duarte
il 2 Mag 2020
Ameer Hamza
il 2 Mag 2020
What is the name of these variables in the image you shared?
Juan Sebastian Corredor Duarte
il 2 Mag 2020
Ameer Hamza
il 2 Mag 2020
To use with from workspace block. The matrix must have two columns. The first column is the time values, and the second column is data. You need to define these four variables using the format I described.
Juan Sebastian Corredor Duarte
il 2 Mag 2020
Ameer Hamza
il 2 Mag 2020
Something like this
T_stop = % wtite the stop time
TORQUEM1 = % column vector of values TORQUEM1
TORQUEM2 = % column vector of values TORQUEM2
TORQUEM3 = % column vector of values TORQUEM3
TORQUEM4 = % column vector of values TORQUEM4
t = linspace(0, T_stop, numel(TORQUEM1)).';
TORQUEM1 = [t TORQUEM1];
TORQUEM2 = [t TORQUEM2];
TORQUEM3 = [t TORQUEM3];
TORQUEM4 = [t TORQUEM4];
Juan Sebastian Corredor Duarte
il 3 Mag 2020
Juan Sebastian Corredor Duarte
il 3 Mag 2020
Ameer Hamza
il 3 Mag 2020
How does TORQUEM1 change with time? You said that you want to input the value of TORQUEM1 in your model, but if it just a single value, then From Workspace cannot read it. From Workspace block needs all the values in advance, it cannot read a changing variable.
Juan Sebastian Corredor Duarte
il 3 Mag 2020
Ameer Hamza
il 3 Mag 2020
Why are you using asignin() to write it base workspace? Simply output the variable from the MATLAB function block and use it in your Simulink model.
Juan Sebastian Corredor Duarte
il 3 Mag 2020
Modificato: Juan Sebastian Corredor Duarte
il 3 Mag 2020
Ameer Hamza
il 3 Mag 2020
Output another variable like this
function [sys,x0,str,ts,torque] = quadrotor_dynamics(t,x,u,flag, quad, x0, groundflag)
and change the block with assignin like this
if i==1
torque=tau(1);
elseif i==2
torque=tau(2);
elseif i==3
torque=tau(3);
else
torque=tau(4);
end
Juan Sebastian Corredor Duarte
il 3 Mag 2020
Ameer Hamza
il 3 Mag 2020
You will see another output port on the block.
Juan Sebastian Corredor Duarte
il 3 Mag 2020
Ameer Hamza
il 3 Mag 2020
It shows the lines containing torque=... does not even run in each iteration. You can add the line
torque = 0
at the beginning of the function.
Juan Sebastian Corredor Duarte
il 3 Mag 2020
Categorie
Scopri di più su Event Functions in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



