4

尝试在 Matlab 中设计以下内容:

** loop start;
   y(:,i) = function of x;
   z(:,i) = function of x;
   plot(x,y(:,i))   on figure 1, hold all;
   plot(x,z(:,i))   on figure 2, hold all;
** loop end;
   add title, legend, etc for figure 1 (NB: we have multiple lines);
   add title, legend, ets for figure 2 (NB: same, have multiple lines for the legend);`

尝试了多种组合,但运气不佳。设法获得 2 个数字,但只有 2-nd 显示多行,而不是第一行。并且无法弄清楚如何正确地为这两个添加图例。

4

2 回答 2

4

为每个图形和每个轴对象保存一个句柄:

fh1 = figure;
hold all;
ah1 = gca;

fh2 = figure;
hold all;
ah2 = gca;

for i=1:N
    y(:,i) = function of x;
    z(:,i) = function of x;
    plot(ah1, x, y(:,i)); %# tell it which axis to use (ah1)
    plot(ah2, x, z(:,i)); %# (ah2)
end

legend(ah1, ...) %# legend options here
legend(ah2, ...) %# and the other legend

%# note: you can set figure properties for each using fh1, fh2 handles.
于 2012-08-26T22:31:14.800 回答
0

你可以这样做:

figHandle1 = figure(1);
figHandle2 = figure(2);

然后,当您想在该图上绘图时,请执行以下操作:

figure(figHandle1) %Plot on figure 1
%ie plot(someStuff)
figure(figHandle2) %Plot on figure 2

标题和内容也一样,您只需要通过以下方式确定哪个数字:

figure(handle);

希望这可以帮助。

于 2012-08-26T22:30:58.013 回答