Extra dimension on simulink output

조회 수: 27 (최근 30일)
Zachary
Zachary 2014년 10월 15일
편집: Alessio Chieffalo 2017년 7월 13일
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?

채택된 답변

Jon Boerner
Jon Boerner 2014년 10월 16일
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:
  1. Open the model configuration parameters (the gear icon in the toolstrip for the model)
  2. Go to the "Data Import/Export" pane
  3. In the "Save to Workspace" section, there is a subsection "Time, State, Output"
  4. In this subsection, there is an option "Limit data points to last:"
  5. Make sure this option is checked and change the number to 1
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.

추가 답변 (1개)

Alessio Chieffalo
Alessio Chieffalo 2017년 7월 13일
편집: Alessio Chieffalo 2017년 7월 13일
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?

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by