Add table variable (addvars) with changing variable names
조회 수: 12 (최근 30일)
이전 댓글 표시
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
Peter Perkins
2019년 1월 23일
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?
답변 (1개)
Fangjun Jiang
2019년 1월 11일
Seems no problem running the following code:
clear;
A=1;
A1=2;
A2=3;
B=who('A*')
T=table;
addvars(T,B);
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Logging에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!