【问题标题】:How to assign figure property with movegui() on Matlab subplot?如何在 Matlab 子图上使用 movegui() 分配图形属性?
【发布时间】:2016-10-02 10:02:19
【问题描述】:

我需要为子图 (1-2) 分配单位 英寸。 我为该图添加了 movegui(),之后我开始收到错误。 没有它,我不会收到错误消息。 代码

hFig3=figure('Units', 'inches', 'Name', 'Time, Potential, T-p, T-p tiff');
movegui(hFig3,'northeast'); % without this, you do not get the error
% TechnicalMonitoring
b1=subplot(2,2,1); 
b2=subplot(2,2,2); 
b3=subplot(2,2,3); 
b4=subplot(2,2,4); 

% b1, b2 
hFig3.Children(1).Units = 'inches';
hFig3.Children(2).Units = 'inches';

错误

No public property Units exists for class matlab.graphics.GraphicsPlaceholder.

Error in code_1s (line 488)
    hFig3.Children(1).Units = 'inches';

Matlab:2016a
操作系统:Debian 8.5 64 位

【问题讨论】:

    标签: matlab matlab-figure subplot


    【解决方案1】:

    我无法重现您的错误,但如果您想为特定的子图分配单位,请为它们明确分配,而不是依靠 hFig3.Children 以特定顺序返回子图。您可以通过将axes 的数组传递给set 来做到这一点。

    set([b1 b2], 'Units', 'inches')
    

    或者如果你真的想使用点符号,你可以单独使用它们

    b1.Units = 'inches';
    b2.Units = 'inches';
    

    或者你可以在创建它们时设置它

    subplot(2, 2, 1, 'Units', 'Inches');
    

    【讨论】:

    • 我真的很喜欢你的第一个数组提案,我非常想念它,我应该能够学会使用它,因为没有它我的代码看起来真的很糟糕;因为我有很多数字并且在交互数字/子图/...方面有很多复杂性
    • @Masi 尽可能尝试显式更改图形对象,而不是假设它们存储在某处或它们是当前对象。这样你就可以得到一个无论如何都可以工作的 GUI!
    • 你能不能对像set([hFig], 'Position', unitsPerInches(:,index);这样的图形对象做类似的事情。目前,我有hFig.Position = unitsPerInches(:,index);,但实际上,我还有其他需要相同unitsPerInches 的数字,所以可能有set([hFig, hFig2], 'Position', unitsPerInches(:,index);。 ——你怎么看?
    猜你喜欢
    • 1970-01-01
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 2012-03-08
    • 2012-09-29
    • 2022-01-25
    相关资源
    最近更新 更多