Add table variable (addvars) with changing variable names
10 views (last 30 days)
Show older comments
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 Comments
Peter Perkins
on 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?
Answers (1)
Fangjun Jiang
on 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);
See Also
Categories
Find more on Data Logging in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!