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 *

Recent Posts

  • Spanish Juggling problem
  • Changing the maximum upload file size with Nextcloud in a docker-compose setup
  • Shrinking a QNAP Virtualization Station disk image
  • Indexed Priority Queue in C++
  • Efficient Union-Find in C++ – or: Disjoint-set forests with Path Compression and Ranks

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

Archives

  • January 2023
  • December 2022
  • 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

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

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