Azzera filtri
Azzera filtri

How can I programmatically access specific variables that are dynamically loaded?

19 visualizzazioni (ultimi 30 giorni)
I am trying to load a specific variable and use it in my program. When I do so (using the following code), the data comes in as a struct (e.g. x.out1, x.out2, etc.)
x=load(strcat('Testfiles\', testcase.filename),strcat('out',num2str(num_videos)));
Because the content of x is dynamic, I cannot explicitly state which outN I am looking for in the code.
vid=x.out(...);
Because this is not a string, but a variable assignment, I cannot use strcat('out',num2str(num_videos)).
How can I assign the loaded variable to vid?
Thanks, Sean

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 22 Lug 2011
Use fieldnames() to get your true variable names then use dynamic field name technique to get the value.
VarNames=fieldnames(x);
MyVarName=VarNames{1};
Value=x.(MyVarName)

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by