将现有的MATLAB图绘制到另一个图中 [英] Plotting an existing MATLAB plot into another figure

查看:602
本文介绍了将现有的MATLAB图绘制到另一个图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用plot命令绘制图形,然后使用set命令更改了其许多属性.我还存储了图的句柄(例如h1).

I used the plot command to plot a figure and then changed lots of its properties using set command. I also store the handle of the plot (say h1).

我需要的是稍后在代码中使用该手柄再次绘制相同的图形.我检查了plot命令,但没有找到任何接受handle的版本.我还想到了获取Xdata和Ydata并使用它们重新绘制相同的图形.

What I need is to use the handle to plot the same figure again later in my code. I checked the plot command and did not find any version that accepts handle. I also thought of getting the Xdata and Ydata and use them to re-plot the same figure.

最简单的解决方案是什么?

What is the simplest solution?

PeterM建议的基于copyobj的有效示例代码.

Edit 1: A working sample code based on copyobj that PeterM suggested.

hf(1) = figure(1);
plot(peaks);

hf(2) = figure(2);
plot(membrane);

hf(3) = figure(3);
ha(1) = subplot(1,2,1);
ha(2) = subplot(1,2,2);

for i = 1:2
    hc  = get(hf(i),'children');
    hgc = get(hc, 'children');
    copyobj(hgc,ha(i));
end

我还发现了可以复制数字(包括图例).

Edit 2: I also found this function that can copy figures (including legend) into a subplot.

推荐答案

我以前遇到过这种情况.根据您尝试执行的功能, copyobj 可能是合适的.此功能使您可以获取一个轴的内容并将其复制到新图形中.

I have run into this situation before. Depending on what you are trying to do the function copyobj may be appropriate. This function lets you take the contents of one axes and copy it to a new figure.

这篇关于将现有的MATLAB图绘制到另一个图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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