Retrieving variables from multiple workspaces and use them in for loop
Afficher commentaires plus anciens
I've generated (many) folders which contain each a workspace (named wksp) and some figures. The name of the folders are generated automatically and depend on parameter values, alpha and beta, given in my program. Ex:
mkdir(sprintf('/Users/OUTPUTalpha%gbeta%g',alpha,beta)).
Suppose I've three numerical values for alpha, while beta remains unchanged (and is equal to betavalue). How do I retrieve variables from workspace (wksp) in the different folders with the help of a for-loop, and plot these variables into the same figure?
What I try is something like this:
alphavalues = [1 20 300];
Path(1,:) = '/Users/OUTPUTalpha1gbetavalue ';
Path(2,:) = '/Users/OUTPUTalpha20gbetavalue ';
Path(1,:) = '/Users/OUTPUTalpha300gbetavalue';
figure;
for i = 1:length(alphavalues)
load fullfile('Path(i,:)','wksp.mat')
plot(variable)
hold on;
end
hold off;
I get an error message saying that the file sprintf(path(i,:)) does not exist.
While the pathname shows nicely when typing
sprintf(Path(1,:)), for example, in the command window,
it only returns
ans = sprintf(Path(1,:))/wksp.mat when using fullfile.
Thank you for your help.
Réponses (1)
Walter Roberson
le 9 Juin 2017
thisdata = load( fullfile( Path(i,:), 'wksp.mat') );
plot(thisdata.variable)
1 commentaire
Mherr
le 11 Juin 2017
Catégories
En savoir plus sur Whos dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!