MATLAB: How to programmatically access specific variables that are dynamically loaded

assignmentdynamicdynamically loadedloadvariablevariable assignment

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

Best Answer

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)