How do i create an M code to plot all graphs within the workspace?
34 views (last 30 days)
Show older comments
Hi,
How do i create an M code to plot all graphs within the workspace? This is my attempt but all it ends up doing is putting the variable names in to a, as opposed to the data. I've had a little fish around for the answer but i can't seem to find anything suitable.
i = 0;
WorkspaceVar = who;
while i < size(WorkspaceVar,1);
i = i+1;
figure(i);
clf(figure(i));
set(gcf,'Color','white')
a = WorkspaceVar(i);
plot(a(:,1),a(:,2),'blue')
xlabel('Frequency (MHz)');
ylabel('Magnitude');
title(WorkspaceVar(i));
disp(['Pass ' num2str(i)]);
end
Thanks Bobby
0 Comments
Answers (1)
Guillaume
on 20 May 2015
A for loop would make more sense than a while loop in your case.
wvar = who;
for v = 1:numel(wvar) %avoid using i, or j, the imaginary units
vvalue = eval(wvar{v});
hfig = figure(v);
clf(hfig);
set(hfig, 'Color', 'white')
plot(vvalue(:,1), value(:,2), 'blue')
xlabel('Frequency (MHz)');
ylabel('Magnitude');
title(wvar{v});
disp(sprintf('Pass %d', v));
end
The code above will only work if all the variables in the workspace have at least 2 columns.
BUT, the fact that you want to plot multiple variables of unknown names may be an indication that you'be used a strongly discouraged method of generating these variables in the first place. See this answer for the details. It would have been better if you'd put all your graphs in a single cell array in the first place.
0 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!