将图形大小分配给具有给定句柄的图形(MATLAB)

时间:2010-04-07 14:15:43

标签: matlab figures

有没有办法将图形的outerposition属性赋值给具有给定句柄的图形?

例如,如果我想将图形定义为图1,我会使用:

 figure(1)
 imagesc(Arrayname) % I.e. any array

我还可以使用代码更改图形的属性:

figure('Name', 'Name of figure','NumberTitle','off','OuterPosition',[scrsz(1) scrsz(2) 700 700]);

我是否可以使用属性名将outerposition属性分配给指定为图1的图形?

我问这个的原因是因为我正在使用一个名为save2word的命令(来自MATLAB文件交换)来保存我对一个word文件所做的函数的一些图,我想限制数字的数量我这是开放的。

我的其余代码是:

plottedloops = [1, 5:5:100]; % Specifies which loops I want to save


GetGeometry = getappdata(0, 'GeometryAtEachLoop') % Obtains a 4D array containing geometry information at each loop


NumSections = size(GetGeometry,4); %Defined by the fourth dimension of the 4D array

for j = 1:NumSections
    for  i = 1:plottedloops
    P = GetGeometry(:,:,i,j);

    TitleSize = 14;
    Fsize = 8;
    % Save Geometry

    scrsz = get(0,'ScreenSize'); %left, bottom, width height   


  figure('Name', 'Geometry at each loop','NumberTitle','off','OuterPosition',[scrsz(1) scrsz(2) 700 700]); This specifies the figure name, dims etc., but also means multiple figures are opened as the command runs.

% I have tried this, but it doesn't work:
% figure(0, 'OuterPosition',[scrsz(1) scrsz(2) 700 700]);

    imagesc(P), title('Geometry','FontSize', TitleSize), axis([0 100 0 100]);

    text(20,110,['Loop:',num2str(i)], 'FontSize', TitleSize); % Show loop in figure
    text(70,110,['Section:',num2str(j)], 'FontSize', TitleSize);% Show Section number in figure

    save2word('Geometry at each loop'); % Saves figure to a word file

end

由于

2 个答案:

答案 0 :(得分:3)

如果在创建图形时捕获图形手柄

figH = figure;

您可以随时指定属性

set(figH,'OuterPosition',[scrsz(1),scrsz(2),700,700]);

您还可以在矢量中收集图形手柄,然后一次设置所有尺寸。

如果由于某种原因无法捕获图形句柄,可以使用findall查找具有特定名称的图形,或使用gcf来获取当前句柄(最后选择/打开) )图。

答案 1 :(得分:0)

以下是一些建议/更正:

  • 你的第二个for循环应该是这样的:

    for i = plottedloops
    

    这是因为plottedloops 已经一个数组,并且您希望i在每次循环中对数组中的每个连续值进行处理。例如,for loop的常见表单是:

    for i = 1:someScalarValue
    

    术语1:someScalarValue 为您创建数组。

  • 看起来你想要在图形窗口中绘制一些东西,然后用save2word保存它,然后绘制其他东西,然后保存它等等。因此,我建议创建你的图形窗口< em>在你的for循环外面,只需在循环中重新绘制窗口内容。如果你在循环外移动这两行:

    scrsz = get(0,'ScreenSize'); %left, bottom, width height   
    figure('Name', 'Geometry at each loop','NumberTitle','off',...
           'OuterPosition',[scrsz(1) scrsz(2) 700 700]);
    

    然后你应该只打开一个数字。