Add table variable (addvars) with changing variable names

10 Ansichten (letzte 30 Tage)
Rodolfo Villanueva
Rodolfo Villanueva am 11 Jan. 2019
Kommentiert: Peter Perkins am 23 Jan. 2019
I have a simulink simulation platform where the names of the variables, and later the logged data, changes. These variables are stored in the workspace with a variable but defined format.
I normally create a table and add the variables in a certain order to create a data summary. But because the name of the variable changes, I need to program the addvars function to first find the variable names, and then add them to the table.
I have not been able to do this. I tried feeding the results from a ''who'' variable search, but it does not accept it as a input. I believe it has to do with the way addvars works.
B = who('A_*') %Returns variables in workspace that start with A_
StreamsSummary = addvars(StreamsSummary,B)
The above code gives an error, does not matter if the result from the who command is one variable or ten.
Is there a way to work around this?
Thanks !
  3 Kommentare
Rodolfo Villanueva
Rodolfo Villanueva am 12 Jan. 2019
Agreed! As a newbie, I've been reading into this, but I honestly do not know if it would work in my case:
  1. I'm building a simulation platform on simulink where the units and designed to be used change all the time, depending on the user.
  2. For this reason, I normally wont know what names or order or modifications a user can make.
  3. The simulation data can be stored in multiple ways, but after trying a bit, using the To Workspace block seemed the most flexible choice. Logging signals directly inside simulink does not allow me to easily create small clickable routines that tidy simulation data and export it to excel for end-users.
  4. I guess in summary, the biggest change I have is I log data signals from simulink signals, which can vary in name constantly. My challenge is to be write code that can consistently keep up with these changes, log the data during a simulation, put it in a table in an orderly manner, and export it.
I would definitely appreciate any insight into this.
Thanks!
Peter Perkins
Peter Perkins am 23 Jan. 2019
I'm no expert on exporting data from SL, but there is quite a lot of flexibility there. And I think Stephen's advice is sound -- what you are doing forces you to use something like eval.
Is it possible to create a struct in the workspace with a fixed name but possibly varying field names, and then use struct2table? Or is it possible for you to log directly to a timetable?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 11 Jan. 2019
Seems no problem running the following code:
clear;
A=1;
A1=2;
A2=3;
B=who('A*')
T=table;
addvars(T,B);
  1 Kommentar
Rodolfo Villanueva
Rodolfo Villanueva am 12 Jan. 2019
Yes, this runs, but if you noticed, you only added the names of the variables to the table. It didnt retrieve the variable data and added it to the table. In this case, you get a 3x1 table with the names of the variables inside, not the values.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by