Can I dynanically reference a variable name, similar to dynamic field references?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a large mat file containing many different variables. I would like to load and process the variables by working through a list of their names. Is there a way other to do this than eval, perhaps similar to dynamic field references as shown in the non-working example below? Saving the variables as fields isn't an option, because the resulting structure is too big to load, and I don't need all the variables at once.
listOfVars = {'dog', 'cat', 'hamster', 'budgie'}; % Example big variables in the file
for iVar = [1 3] % Only load and process some of the variables
load('bigFile.mat', listOfVars{iVar}); % Load a single variable
% Manipulate the variable using a dynamic reference to its name. Doesn't work, of course.
plot((listOfVars{iVar}).weight, (listOfVars{iVar}).foodConsumed, 'x');
hold on;
end
0 Commenti
Risposta accettata
Walter Roberson
il 13 Mag 2014
You should be able to use the command form of load together with dynamic field names.
thisdata = load('bigFile.mat', listOfVars{iVar});
plot(thisdata.(listOfVars{iVar}).weight, thisdata.(listOfVars{iVar}).foodConsumed, 'x');
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown 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!