首页 文章

在一个图中显示多个.fig文件

提问于
浏览
0

我正在尝试编写一个相对简单的函数,它允许我绘制任意数量的图形(以前保存为.fig文件),一个接近另一个 .

我在网站上寻找解决方案,但它对我不起作用 . 此外,我几乎有我的代码,因为输出几乎是我想要的:我确实把两个数字放在正确的位置,但在两个单独的窗口和第三个窗口正确合并两个输入,但它们看起来很奇怪,分辨率较低!所以总共得到三个输出 .

这是我的代码,希望你能帮助我 . (尝试使用自己的.fig文件,检查是否还有像我这样的三个错误输出) .

function SubPlotFig (varargin)

for i = 1:nargin
hf = hgload(varargin{i});
ax(i) = findobj(hf,'Type','axes');
end

hc = figure;
for i = 1:nargin
subplot(1,2,i,ax(i)); 
copyobj(ax(i),hc); 
end

Attachment_1 Attachment_2

2 回答

  • 0

    当您调用 hgload 时,它将打开.fig文件中的图形并显示它 . 您在第一个循环内执行此操作,因此您将看到每个输入的数字 . 您看到的数字正是您为每个数字保存的数字 .

    for i = 1:nargin
        hf = hgload(varargin{i});           % <---- Creates a figure
        ax(i) = findobj(hf,'Type','axes');
    end
    

    在第二个循环中,为刚打开的图形中的每个 axes 创建一个 subplot . 这些当然会变得更小,因为你现在将多个 axes 放在 figure 中,这是默认大小 . 他们不想增加你的身材 .

    % Create all of the subplots
    hc = figure;
    for i = 1:nargin
        hax = subplot(1,2,i,ax(i)); 
        copyobj(ax(i),hc); 
        colorbar(hax);
    end
    
    % Make sure we are using the jet colormap
    colormap(jet)
    
    % Get the current figure position
    pos = get(hc, 'Position');
    
    % Double the width since you now have two plots
    set(hc, 'Position', [pos(1:2) pos(3)*2, pos(4)])
    
  • 0

    问题是色彩图 . 现在它解决了 . 这是正确的代码,对其他人有用:)

    function SubPlotFig (varargin)
    
    for i = 1:nargin
    hf = openfig(varargin{i},'reuse');
    cm = colormap;
    c(i) = findobj(hf,'Type','Colorbar');
    ax(i) = findobj(hf,'Type','Axes');
    end
    
    hc = figure;
    for i = 1:nargin
    subplot(1,2,i,ax(i));
    copyobj(ax(i),hc); 
    colormap(ax(i),cm);
    copyobj([c(i),ax(i)],hc);
    end
    

相关问题