SIMULINK: save predefined data to workspace with EML

2 views (last 30 days)
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 Comment
Ryan Livingston
Ryan Livingston on 2 Apr 2014
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?

Sign in to comment.

Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!