【问题标题】:MATLAB: How do I save an axes that is generated within a GUI to a '.fig' file?MATLAB:如何将在 GUI 中生成的坐标区保存到“.fig”文件中?
【发布时间】:2013-10-27 22:16:07
【问题描述】:

我在 MATLAB 中以编程方式创建了一个 GUI,它允许用户调整某些参数以更改轴上显示的数据。我希望用户能够将该轴保存为 MATLAB 图。我尝试了多种通过 Google 和 MATLAB 文档找到的方法,但都没有奏效。

我当前的非工作代码:

% Creation of the axes ui component
a1 = axes('Units','pixels','Position',[20,18,270,255],'box','on');

% Skipped ahead to callback for 'save' menu item
function menu1_callback(~,~)
    % Creates a new figure
    f2 = figure;
    % Copies the axes a1 to the new figure
    copyobj(a1,f2);
    % Save the new figure
    saveas(gcf,'filename','fig');
end

这是 MATLAB 生成的错误:

Error using getProxyValueFromHandle (line 15)
Input must be a valid handle.

Error in plotedit (line 91)
                [varargout{1:nargout}] = feval(args{:});

Error in specgraph.barseries/preserialize (line 10)
peerVals = plotedit({'getProxyValueFromHandle',hPeers});

Error in hgsaveStructDbl (line 80)
        olddata{i} = {hh,preserialize(hh)};

Error in hgsave (line 62)
    hgS = hgsaveStructDbl(h, SaveAll);

Error in saveasfig (line 7)
hgsave( h, name );

Error in saveas (line 126)
    feval( ['saveas' format], h, name )

Error in GBdataVisualiser2/menu1_callback (line 165)
        saveas(gcf,'filename','fig');

Error while evaluating uimenu Callback

【问题讨论】:

    标签: matlab user-interface


    【解决方案1】:

    您似乎将错误的句柄传递给函数saveas。我认为gcf 函数仅在您处理在单独屏幕中打开的普通图形时才有效,而不是嵌入在 GUI 上的图形。

    我会尝试:

    % Skipped ahead to callback for 'save' menu item
    function menu1_callback(~,~)
        % Creates a new figure
        f2 = figure;
        % Copies the axes a1 to the new figure
        copyobj(a1,f2);
        % Save the new figure
        saveas(f2,'filename','fig');
    end
    

    【讨论】:

    • 恐怕这会产生一个几乎相同的错误,只是代码的变化不同:Error in GBdataVisualiser2/menu1_callback (line 165) saveas(f2,'filename','fig');
    猜你喜欢
    • 2016-10-26
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多