Add table variable (addvars) with changing variable names
Mostra commenti meno recenti
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 Commenti
Stephen23
il 12 Gen 2019
"Is there a way to work around this?"
There are ways to work around this, but fundementally your data design forces you to write complex, slow, buggy code that is hard to debug. Read this to know why:
Rodolfo Villanueva
il 12 Gen 2019
Peter Perkins
il 23 Gen 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?
Risposte (1)
Fangjun Jiang
il 11 Gen 2019
Seems no problem running the following code:
clear;
A=1;
A1=2;
A2=3;
B=who('A*')
T=table;
addvars(T,B);
1 Commento
Rodolfo Villanueva
il 12 Gen 2019
Categorie
Scopri di più su Data Logging in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!