- Open the model configuration parameters (the gear icon in the toolstrip for the model)
- Go to the "Data Import/Export" pane
- In the "Save to Workspace" section, there is a subsection "Time, State, Output"
- In this subsection, there is an option "Limit data points to last:"
- Make sure this option is checked and change the number to 1
Extra dimension on simulink output
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Zachary
am 15 Okt. 2014
Bearbeitet: Alessio Chieffalo
am 13 Jul. 2017
I'm running a Simulink model that should send two 3x1 matrices to the workspace. Instead, both of my matrices are 3x1x51, and a corresponding 51x1 matrix called "tout" is produced. How can I prevent my desired matrices from having this third dimension?
0 Kommentare
Akzeptierte Antwort
Jon Boerner
am 16 Okt. 2014
This third dimension corresponds to time. tout lets you map the output matrix to certain times in the simulation. For example, output(:,:,4) was the output of the simulation at time tout(4).
If you are looking for just a single matrix of size 3x1, there are a couple options.
If your model is just a single equation (i.e. you do not need to see the results over time), then you can set the simulation time to 0. This will cause the model to only run one timestep, so you will get a 3x1x1 output.
If you just want the last value of the matrix (what it is at the end of the simulation), then you can index into the output matrix:
squeeze(output(:,:,end))
Note that squeeze changes the dimensions of this last matrix from 3x1x1 to 3x1, which is easier to work with.
The last option for outputting just the matrix for the last timestep would be to limit the number of dat apoints being output. If you are sending data to the workspace by using an 'Out1' block, you can do the following to limit the number of data points:
Now if you run your model, only the last time step should be saved to the workspace. If you are using a To Workspace block, there is an analogous option if you double click on the block.
This documentation page has links to all of the information you might want to know about data export. I would suggest taking a look through, as it will be more through than my explanation above, but feel free to post a comment if you have any questions.
0 Kommentare
Weitere Antworten (1)
Alessio Chieffalo
am 13 Jul. 2017
Bearbeitet: Alessio Chieffalo
am 13 Jul. 2017
I tried your suggested ways about the same problem, but they don't work. I found a solution in the "Model configuration panel" -> "Solver" setting the "stop time" to 0, but the integrator blocks doesn't work (it puts to 0 its own output). This is my code;
clear all
close all
clc
J=[100 0 0
0 100 0
0 0 500];
Omega0=[0.0175 0 -0.0524];
M=[sin(0.01) 0 sin(0.05)];
SimOut=sim('EulerMomentum')
my Simulink model is:
the User-function code in the Simulink model:
function AngAcc = DynamicEq(J_inv,M)
%#codegen
AngAcc=M'*J_inv;
and the outputs are:
What's wrong?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Sources finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!