MATLAB: How to convert signal logging data from Simulink (e.g. logsout data) to create single arrays with the according signal names in the workspace

arraydataexportlogsoutMATLAB

I want to access the singal logging data 'logsout' so that I get single arrays for each logged signal. How can I do this?

Best Answer

Use the small script below to disassemble the signals and to get a single array for each logged signal (line) with the according name.
Note: This script only works for single dimension outputs. This script does NOT work for vectors like bus or mux signals.
%%Export logsout data to single arrays
a = get(logsout);
f = fields(a);
b.Name = a.Name;
b.BlockPath = a.BlockPath;
for i = 3:numel(f)
newfieldname = f{i}(isstrprop(f{i}, 'alphanum')); %remove characters that are invalid in a fieldname
b.(newfieldname) = get(a.(f{i}));
b.(newfieldname).TimeInfo = get(b.(newfieldname).TimeInfo);
outputstring = [newfieldname '= b.(newfieldname).Data'];
eval(outputstring);
end
% OPTIONAL:
% delete obsolete data
clear a b f i newfieldname outputstring