Skip to content
XeveAbout code and problems

Convert dSPACE ControlDesk measurement to MATLAB timeseries that can be used in Simulink

May 11, 2018 1 comment Article Uncategorized nspo

(Updated version here)

  • 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);
Tags: controldesk, convert, dspace, export, matlab, signals, timeseries

1 comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Calendar

May 2018
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  
« Apr   Jul »

Archives

  • January 2021
  • May 2020
  • April 2020
  • July 2018
  • May 2018
  • April 2018
  • March 2018
  • September 2015
  • August 2015
  • June 2015
  • March 2015
  • February 2015
  • September 2014
  • March 2013

Categories

  • Uncategorized

Copyright Xeve 2021 | Theme by ThemeinProgress | Proudly powered by WordPress