How do i create an M code to plot all graphs within the workspace?
이전 댓글 표시
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
답변 (1개)
Guillaume
2015년 5월 20일
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.
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!