Extract variables saved to workspace from simulink

Using the "To Workspace" block, many signals of different sampling time are saved to the workspace as "Structure with time". The results are saved in "simout". As the sampling time is different, the data consists of unequal length, and cannot be appended within a single array. Further, two logging intervals have been used.
I would like to combine the signals of sample rate 100ns, 1us, 15us and 150us so that the data for each logging interval can be retrieved in one go (or I would have to read each array (variable? - not sure of the term to be used)).
The time is stored in "tout" within "simout", and each signal is saved with the name specified in "To Workspace". The same is attached.
Is there a way to access these variables (arrays??) using some simplified method? I'm new to programming and not yet familiar with all the terms.

5 commentaires

Jon
Jon le 18 Oct 2023
Please attach your Simulink model, or a simplified one that reproduces the problem, so that we can see exactly what you are doing
you might combine all your signals in one output directly in your simulink model
but you need first to sample all your data to a common sampling rate (using the zero hold block to do this on data that are sampled at a different rate)
@Mathieu NOE I have four different sampling rates in the simulation. Seven of them are at one rate, 9 at another, 8 at another and 20 at the simulation sample time. I'm using this to analyse the behaviour of the controllers, for which it is easier if the signals are reproduced at their sampling rate itself.
Is there a way to obtain the name and size of the signals (variables/array) within the structure? I'm thinking if it would be possible to combine signals (variable/array) of the same size within the structure into a single matrix (as a mat file or workspace variable), which is what I require.
For now, I've written a long program that will extract the logging intervals of each signal and stored them in separate variables in the workspace, makes it difficult to keep track of multiple variable names.
I hope there could be a way to extract signals of similar size along with their names and then store them in a single mat file. If this is possible, then extracting the logging intervals would be relatively easy, and needn't be done seoarately for each signal. Hope this explains what's on my mind.
Thanks!
Mathieu NOE
Mathieu NOE le 19 Oct 2023
Modifié(e) : Mathieu NOE le 19 Oct 2023
sorry to insist but why not resample (in your simulink file) all the data at the simulation sampling rate ? those who runs at slower sampling rate would have multiple values (interpolation) but that doesn't seem to be an issue IMO
@Mathieu NOE I've extracted the data at different sampling rates and have them in 6 separate tables. 3 are for logging interval one and the other three for logging interval two. Each variable in the table is a column vector.
While column heading in spreadsheets are read into MATLAB as variable name, the variable name is not converted to column heading in excel. Only the data (numerical values) are imported into .xlsx file (when table contents are copied and pasted in an .xlsx file).
Is there a way to export the variable names in a table to spreadsheet along with the values?

Connectez-vous pour commenter.

 Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 26 Oct 2023

0 votes

I would suggest you saving the data in time series format and use API to process it.

Plus de réponses (0)

Catégories

En savoir plus sur Prepare Model Inputs and Outputs dans Centre d'aide et File Exchange

Produits

Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by