SIMULINK: save predefined data to workspace with EML

2 次查看(过去 30 天)
Dear all,
Simulink constains a ToWorkSpace block that allows saving data into workspace.
Also it is possible to define a similar process with EML as follows:
persistent index;
if isempty(index), index = 0; end;
index = index + 1;
eml.extrinsic('assignin');
eml.extrinsic('evalin');
% save the variables in workspace
assignin('caller', 'tmp1', u);
assignin('caller', 'tmp2', uint32(index));
evalin('caller', 'data2(uint32(tmp2),:) = tmp1;');
(if something simpler, I am welcome).
Let us say that my simulink model contains 1000 data that I possibly want to save depending on the simulation to be performed.
Is there a clever way through an EML to perform the saving of some data according to a set of data names defined in workspace? For instance, I would like to save some outputs of a given block that are included in the predefined set of names. Something like:
data_to_be_saved = {'output1','output3'};
h = get_param(block_name, 'PortHandles');
Varnames = get(h.outport(1),'SignalNameFromLabel' )
for k=1:length(Varnames)
if strmatch(Varnames{k},data_to_be_saved,'exact')
assignin('base',VarNames{k},data_values);
end
end
It is possible to define an enabled block for each ToWorkspace block with a dedicated flag but Simulink lisibility becomes poor and it requires hours for 1000 data.
Thanks in advance, Petru
  1 个评论
Ryan Livingston
Ryan Livingston 2014-4-2
If you're still looking into this, it would be helpful to know why you want to save the various variables to other workspaces. Is it just to pass the outputs of your simulation or another reason?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by