Skip to content
XeveAbout code and problems

Convert dSPACE ControlDesk measurements to MATLAB/Simulink timeseries (updated)

May 29, 2018 4 comments Article Uncategorized nspo

(Old version here)

  • With this updated MATLAB script, multiple dSPACE ControlDesk measurements can be imported with a single execution
  • The result is saved as a tscollection (collection of timeseries) and all signals are saved with their corresponding name
  • Access imported data with Simulink ‘From Workspace’ block and, e.g., dsp_tscs{1}.my_signal

Example console output (files can be selected within a GUI window):

>> import_dspace_mat_to_simulink_ts

Time Series Collection Object: testmode2-y120-leer.mat

Time vector characteristics

      Start time            0 seconds
      End time              1.779970e+01 seconds

Member Time Series Objects:

      CLOCK
      (...)
      yn_soll_U_s
      yp_vorg_cm_s

Time Series Collection Object: testmode2-y120-leicht.mat

Time vector characteristics

      Start time            0 seconds
      End time              2.220077e+01 seconds

Member Time Series Objects:

      CLOCK
      (...)
      yn_soll_U_s
      yp_vorg_cm_s

Time Series Collection Object: testmode2-y120-schwer.mat

Time vector characteristics

      Start time            0 seconds
      End time              1.570162e+01 seconds

Member Time Series Objects:

      CLOCK
      (...)
      yn_soll_U_s
      yp_vorg_cm_s

-- Saved data from testmode2-y120-leer.mat in tscollection dsp_tscs{1}
-- Saved data from testmode2-y120-leicht.mat in tscollection dsp_tscs{2}
-- Saved data from testmode2-y120-schwer.mat in tscollection dsp_tscs{3}

Script:

% dspace mat export to tscollection that can be used with 'From
% Workspace' in Simulink

[filenames, paths] = uigetfile('*.mat', 'Select dSPACE mat files', 'MultiSelect', 'on');
dspace_files = cellstr(fullfile(paths, filenames));

filenames = cellstr(filenames);

% store all tscollections in a cell array (so multiple files can be loaded at once)
dsp_tscs = {};

for i=1:length(dspace_files)
current_data = importdata(dspace_files{i});


ynames = {current_data.Y.('Name')};
ynames = matlab.lang.makeUniqueStrings(ynames);

dsp_ts = [];
for j=1:size(current_data.Y, 2)
    varname = strcat('', ynames{1,j});
    ts = timeseries(current_data.Y(j).Data, current_data.X(1).Data, 'Name', varname);
    dsp_ts = [dsp_ts; ts]; % not efficient
end


dsp_tsc = tscollection(num2cell(dsp_ts));
dsp_tsc.Name = filenames{i};

dsp_tscs{i} = dsp_tsc;

dsp_tscs{i}
end

for i=1:length(filenames)
   fprintf('-- Saved data from %s in tscollection dsp_tscs{%d}\n', filenames{i}, i); 
end

clear ts dsp_ts dsp_tsc current_data dspace_files filenames i j paths ynames varname ans;
Tags: controldesk, dspace, export, file, mat, matlab, measurement, simulink, timeseries, tscollection

4 comments

  • Michel October 5, 2019 at 09:37 Reply

    which matlab version does this script work on? I used it on matlab 2013b but it gave me the following error:
    ================
    Undefined variable “matlab” or class “matlab.lang.makeUniqueStrings”.

    Error in import_dspace_mat_to_simulink_ts (line 20)
    ynames = matlab.lang.makeUniqueStrings(ynames);
    ================

    any chance you can help?

  • michel October 5, 2019 at 09:42 Reply

    I actually have used the code on matlab 2018 and it worked, any chance you can hint to a workaround for it to work on 2013b?

    • nspo November 23, 2019 at 17:14 Reply

      Hi Michel,
      the function matlab.lang.makeUniqueStrings was introduced in MATLAB R2014a, so you need to either (a) use a version >=R2014a or (b) reimplement the functionality of this method. It just makes sure that you do not have duplicate names, e.g. by creating the names “yval_1″,”yval_2” instead of “yval”,”yval”. If that’s not a problem with your data you might be able to (c) just comment out line 20 which calls the function.

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 2022 | Theme by ThemeinProgress | Proudly powered by WordPress