tags:

views:

247

answers:

2

Hi,

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

+1  A: 

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.

Jonas
A: 

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.

gnovice

related questions