How to setup Simulink logs out .mat format?

8 views (last 30 days)
I log a lot of signal in Simulink, with The following setup:
in(i) = in(i).setModelParameter(...
'LoggingToFile', 'On',...
'LoggingFileName', newFileName,...
'SaveFormat', 'Dataset',...
'SaveTime', 'off',...
'SaveState', 'off',...
'SaveOutput', 'off',...
'SaveFinalState', 'off',...
'DSMLogging', 'off',...
'ReturnWorkspaceOutputs', 'on',...
'Profile', 'off',...
'InspectSignalLogs', 'off',...
'DatasetSignalFormat', 'timeseries'...
The version 7.3 .mat size is almost 2-3 times larger than the version 7.0. That is why I would like to create a version 7 .mat, but it seems Simulink will create a 7.3 mat file anyway. (In the preferences > General > Mat-File - 7.0 option is selected but not really matters which one I select.)
If I load the .mat to the matlab workspace and call
data = load('FileFromSimulink.mat');
save('FileFromSimulink.mat', '-v7', '-struct', 'data')
It will create the expected .mat with reduced size. How can I avoid this extra step to load the files then save it.

Accepted Answer

Sayani on 21 Nov 2022
You can avoid this extra step by adding "Callbacks" to your model. "Callbacks" can be accessed through "Model Properties".
In this particular case, you should add your script to change MAT File version in "StopFcn" under "Callbacks" section. This would then generate a v7.0 MAT File for you automatically everytime the model is executed.
  1 Comment
Szabó Bence Károly
Szabó Bence Károly on 5 May 2023
Thanks for the answer. This is the solution i use now, but still feels like a workaround to me.

Sign in to comment.

More Answers (1)

Muthukumar Ganesan
Muthukumar Ganesan on 20 Aug 2022
In the newer versions of matlab by default, Simulink creates .mat file with version 7.3
You can add these commands in Model Properties -> Callbacks -> StopFcn
data = load('FileFromSimulink.mat');
save('FileFromSimulink.mat', '-v7', '-struct', 'data');
clear data;


Find more on Simulink Environment Customization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!