1

In Matlab I have a function calling a set of parameters. I have 3 sets, and I can call them individually and plot them.. No problems there. But I want to be able to compare them in one single plot. Meaning: is there a way, that I have get all three plots into a single plot?

function [GE,SI,RES,T] = glusim(parameter,Data) [...] If I call glusim(1,Data) I use a set of parameters, and gets a plot. If I call glusim(2,Data) I use another set of parameters and get a plot. If I call glusim(3,Data) I use a third set of parameters and get a plot. I want to compare all 3 in one plot.

How do I do that?

4

1 回答 1

1

该命令hold on允许您在现有轴上绘图,而不会删除已经绘制的内容。

或者,您可以使用hold allwhich 行为相似,但确保其他绘图命令将循环通过预定义的颜色列表(除非您覆盖它)。

因此,您可以如何执行此操作的一个简单示例是:

figure; % Create new figure window
hold on; % Retain graph when adding new ones
plot(Data1);
plot(Data2);
plot(Data3);

稍微复杂一点的答案是,您还需要确保所有绘图命令都绘制到同一个数字。当您调用该plot命令时,它会绘制到任何被认为是“当前图形”的图形。对此的解释有点高级,涉及存储和调用图形句柄,但我在下面提供了一个更详细的示例。

为了更好地控制当前图形是什么图形,您可以将上面的代码修改如下:

h = figure; % Create new figure window, assign figure handle to h
plot(Data1);

% ... Do things other than plotting

figure(h); % When ready to plot, set figure "h" to be the current figure
hold on; % Apply hold to ensure you won't erase previous plots
plot(Data2);

所以要回答你原来的问题,如果绘图是在函数本身内部完成的,你需要确保函数可以访问你想要绘制的图形的句柄。

于 2013-05-23T19:25:56.123 回答