Simulink: create struct with signal names

조회 수: 4 (최근 30일)
Frank
Frank 2011년 12월 27일
Hello,
after the Simulink simulation I would like to have a structure that contains certain signal values. The simples way to do this is to mux all signals together and write them with the block "To Workspace". But here I loose the information about the signal names. Is there an solution to create a structure that contains all signal names? I thought the structure could look like this:
data.time = ...
data.speed = ...
data.dist = ...
Cheers, Frank

채택된 답변

TAB
TAB 2011년 12월 27일
Do you want the output values at each time step or just final simulation value ?.
You can feed your bus output to a embedded matlab block. This bus object will appear as structure in embedded matlab block. In the block function you can write matlab code to save structure to workspace. For example
function fcn(Data)
eml.extrinsic('assignin');
assignin('base','MySavedData',Data);
To use buses in Embedded matlab function, bus objects must be defined in base workspace.
[Edited]
I think this can fullfil your need. Use data logging feature of simulink.
Goto Configuration Parameters -> Data Import/Export -> Check "Signal logging" -> Define any variable name say "LoggedData"
Right Click on Output bus -> set the prorerties as shown in image. Keep Show Propagated singals->on
After running the model a variable "LoggedData" will be created on workspace.
You can acsess you data as
LoggedData.BusOut.a.Data
LoggedData.BusOut.a.Time
and
LoggedData.BusOut.a1.Data
LoggedData.BusOut.a1.Time
  댓글 수: 5
TAB
TAB 2011년 12월 28일
You can access the model name in Embedded matlab block using command 'bdroot' and can use this name as variable name to save data.
function fcn(Data)
eml.extrinsic('assignin');
eml.extrinsic('strcat');
eml.extrinsic('bdroot');
VarName=strcat(bdroot,'_Log');
assignin('base',VarName,Data);
end
But note that, you can not use this Embedded matlab block in code generation. Becuase extrinsic matlab functions do not support code generation.
You can use it for simulation.
Frank
Frank 2011년 12월 28일
Thanks for that. Two more things:
Is there a way to write the whole history of Data into the variable?
How can I write the vector into a structure? e.g. Data.a
Cheers,
Frank.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by