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

发布于 2024-08-28 12:01:16 字数 1639 浏览 3 评论 0原文

有没有办法将图形的外位置属性分配给具有给定句柄的图形?

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

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

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

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

是否有一个属性名称,我可以使用它来将外部位置属性分配给指定为图形的图形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

结束

谢谢

is there a way to assign the outerposition property of a figure to a figure with a given handle?

For example, if I wanted to define a figure as say figure 1, I would use:

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

I can also change the properties of a figure using the code:

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

Is there a propertyname I can use to assign the outerposition property to the figure assigned as figure 1?

The reason I am asking this is because I am using a command called save2word (from the MATLAB file exchange) to save some plots from a function I have made to a word file, and I want to limit the number of figures I have open as it does this.

The rest of the code I have is:

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

end

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的黑色迷你裙 2024-09-04 12:01:16

如果您在创建图形时捕获图形句柄,

figH = figure;

则可以随时分配属性。

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

您还可以将图形句柄收集到向量内,然后一次设置所有大小。

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

If you capture the figure handle when you create the figure

figH = figure;

You can assign properties any time you want

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

You can also gather the figure handles inside a vector, and then set all sizes at once.

If you cannot capture the figure handle for some reason, you can use findall to look for a figure with a specific name, or gcf to get the handle of the current (last selected/opened) figure.

淡淡绿茶香 2024-09-04 12:01:16

以下是一些建议/更正:

  • 您的第二个 for 循环应如下所示:

    for i = 绘制循环
    

    这是因为 plottedloops 已经 是一个数组,并且您希望 i 每次遍历时都采用数组中的每个顺序值循环。例如,for 循环的常见形式是:

    for i = 1:someScalarValue
    

    其中术语 1:someScalarValue 为您创建一个数组。

  • 看起来您想在图形窗口中绘制某些内容,然后使用 save2word 保存它,然后绘制其他内容,然后保存它,等等。因此,我建议创建您的图形窗口 < em>在 for 循环之外,并简单地在循环内重新绘制窗口内容。如果将这两行移到循环之外:

    scrsz = get(0,'屏幕大小'); %左、底部、宽度高度   
    figure('名称', '每次循环的几何图形','NumberTitle','off',...
           '外部位置',[scrsz(1) scrsz(2) 700 700]);
    

    那么您一次应该只打开一个图形。

Here are a few suggestions/corrections:

  • Your second for loop should look like this:

    for i = plottedloops
    

    This is because plottedloops is already an array, and you want i to take on each sequential value in the array for each pass through the loop. For example, a common form for a for loop is:

    for i = 1:someScalarValue
    

    Where the term 1:someScalarValue creates an array for you.

  • It looks like you are wanting to plot something in a figure window, then save it with save2word, then plot something else, then save that, etc. Therefore, I suggest creating your figure window outside your for loops, and simply replotting the window contents within the loop. If you move these two lines outside your loops:

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

    Then you should only have one figure at a time open.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文