Convert dSPACE ControlDesk measurements to MATLAB/Simulink timeseries (updated)
- 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;
4 comments
Leave a Reply Cancel reply
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
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?
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?
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.