Matlab:绘制一个带有不同参数的函数 [英] Matlab: Plot a function with different parameters into

查看:1215
本文介绍了Matlab:绘制一个带有不同参数的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab中,我有一个调用一组参数的函数。我有3套,我可以单独打电话给他们,并绘制他们..没有问题。但我希望能够在一个单一的情节比较他们。意思:有没有办法,我已经把所有三个图绘制成一个图?

函数[GE,SI,RES,T] = glusim(parameter,Data )
[...]
如果我调用glusim(1,Data),我使用一组参数,并得到一个图。
如果我调用glusim(2,Data),我使用另一组参数并得到一个图。
如果我调用glusim(3,Data),我使用第三组参数并得到一个图。
我想在一张图中比较所有3个。



我该怎么做?

解决方案 c 上的命令允许您在现有坐标轴上进行绘图,而不会擦除已绘制的内容。

或者,您可以使用保留所有,它们的行为相似,但可以确保额外的绘图命令将循环通过预定义的颜色列表(除非你重申了这一点)。



所以你可以这样做的一个简单例子是:

 图。 %创建新的数字窗口
保持; %添加新图时保留图
plot(Data1);
plot(Data2);
plot(Data3);

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



为了更好地控制图形是什么目前的数字,你可能会修改上面的代码如下:

  h = figure; %创建新图形窗口,将图形句柄分配给h 
图(Data1);

%...除了绘制

之外的其他东西(h); %准备绘制时,将数字h设置为当前数字
; %应用保持以确保您不会擦除之前的地块
地块(Data2);

所以要回答你最初的问题,如果绘图是在函数本身内完成的,你需要以确保该功能可以访问要绘制的图形的句柄。


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?

解决方案

The command hold on allows you to plot in an existing axes without erasing what's already been plotted.

Alternately you can use hold all which behaves similarly but ensures that additional plot commands will cycle through a predefined color list (unless you overide this).

So a quick example of how you might do this is:

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

The slightly more involved answer is that you also need to ensure that all of your plot commands are plotting to the same figure. When you call the plot command, it plots to whatever figure is considered the "current figure". The explanation of this is a little advanced and involves storing and calling figure handles, but I've supplied a more detailed example below.

To get more control over what figure is the current figure, you might modify the above code as follows:

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);

So to answer your original question, if the plotting is being done inside the function itself, you will need to ensure that the function has access to the handle of the figure you want to plot to.

这篇关于Matlab:绘制一个带有不同参数的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆