Convert dSPACE ControlDesk measurement to MATLAB timeseries that can be used in Simulink
- dSPACE ControlDesk can export measurements to mdf4 files or mat files
- mat file exports can be converted to timeseries with this MATLAB script
- The timeseries can then be imported into Simulink with the ‘From Workspace’ blog
- Multiple signals can be imported at once
Example output:
>> import_dspace_mat_to_simulink_ts --Imported dSPACE mat file C:\Users\Nicolai\Nextcloud\foo.mat into workspace variable dsp_ts --Time: 0.000000 s to 42.399572 s, 423980 steps --2 variables are in dsp_ts: 'In1' 'In1_1'
% dspace mat export to timeseries that can be used with 'From % Workspace' in Simulink [filename, path] = uigetfile('*.mat', 'Select dSPACE mat file'); dspace_file = fullfile(path, filename); dspdata = importdata(dspace_file); % name of workspace var for simulink ts_import = struct(); ynames = {dspdata.Y.('Name')}; ynames = matlab.lang.makeUniqueStrings(ynames); dsp_ts = []; for i=1:size(dspdata.Y, 2) varname = strcat('dsp_', ynames{1,i}); ts = timeseries(dspdata.Y(i).Data, dspdata.X.Data, 'Name', varname); dsp_ts = [dsp_ts; ts]; % not efficient end fprintf('--Imported dSPACE mat file \n%s\ninto workspace variable dsp_ts\n', dspace_file); fprintf('--Time: %f s to %f s, %d steps\n', dspdata.X.Data(1), dspdata.X.Data(end), length(dspdata.X.Data)); fprintf('--%d variables are in dsp_ts:\n', length(dsp_ts)); disp(ynames);
1 comment
Recent Posts
Recent Comments
- Arjun on Fix for Latex4CorelDraw with CorelDraw 2017
- Nigel De Gillern on No wired (LAN) connection in Linux, although everything looks right
- Harald H on Automatically reboot TP-Link router WDR4300 / N750 with bash script
- Gene on Running multiple Django projects on one Apache instance with mod_wsgi
- nspo on NMPC with CasADi and Python – Part 1: ODE and steady state
Leave a Reply