You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how to know the dimension of a figure window and then draw my own according to same dimension
11 views (last 30 days)
Show older comments
If I have a figure window which is open. How can I know its dimesnion? I mean how can I know its size (length and width)? Once I know the dimesnion of the open figure window, then I want to draw my own figure window of the same dimension. How can we do that?
Accepted Answer
Ameer Hamza
on 14 Oct 2020
Edited: Ameer Hamza
on 14 Oct 2020
If it is already open and you don't have its handle, then first get it
fig = gcf(); % handle of current figure;
pos = fig.Position; % contains its position and dimensions
pos is 4 element vector [x y w h]. x and y are the positions of the bottom left corner of the figure window in screen coordinates (by default in pixels). w and h are the width and height of the window (by default in pixels too). Create a new figure at the same position and with the same dimensions
fig2 = figure('Position', pos)
16 Comments
Sadiq Akbar
on 14 Oct 2020
Thank you very much Ameer Hamza for your prompt response. Yes it works. But if I have 8 figures already opened. And I have anothr 9th figure that is in current folder and is not opened.
Now if I want to make the dimesnions of the opened figures identical to the 9th figure, then how can we do that?
Ameer Hamza
on 14 Oct 2020
You cannot do that without opening the figure. If you already know its dimensions, then you can hard-code these values manually, but there is no automatic way without opening the .fig file
fig2 = figure('Position', [10, 10, 500, 500])
Sadiq Akbar
on 14 Oct 2020
Thank you very much for your 2nd prompt response. Ok I got it. If suppose I open the 9th figure also. And I find the dimension by the following command as you told me.
fig = gcf(); % handle of current figure;
pos = fig.Position; % contains its position and dimensions
Now how can I insert this dimension in those 8 figures?
Sadiq Akbar
on 14 Oct 2020
Thank you very much for 3rd response. No. I mean that I have opened all the 8 figures and then opened the 9th figure also. I will determine the dimension of the 9th figure according to the following command as you told me, i.e.
fig = gcf(); % handle of current figure;
pos = fig.Position; % contains its position and dimensions
Now if the 9th figure is a reference for me and I want to make the dimension of all those 8 figures (already opened) identical to the 9th figure, and I don't have their handles, then how can we do that? Say for example their names are fig1, fig2,fig3,....fig8.
Ameer Hamza
on 14 Oct 2020
Ok. Do something like this. Before opening the 9th figure, get the handle of the existing 8 figures
figs = findall(0, 'type', 'figure');
Then open 9th figure, get its handle and extract its position
fig = gcf(); % handle of current figure;
pos = fig.Position; % contains its position and dimensions
the run
[figs.Position] = deal(pos);
Sadiq Akbar
on 14 Oct 2020
Thank you very much for your 4th reponse. Indeed I am very thankful to you for your precious time that you spare for my problem.
Can we make the above a single m file.i.e. If all the 8 figures are opened by my m file.Then if I open the 9th figure also and after that I run your m file and it makes all the 8 figures dimension equal to the dimension of the 9th figure?
Ameer Hamza
on 15 Oct 2020
Ok. You can use the following function
function change_figures_size(fig9)
figs = findall(0, 'type', 'figure');
figs = setdiff(figs, fig9)
pos = fig9.Position;
[figs.Position] = deal(pos);
end
You can pass the handle of 9th figure to this function and it will handle the rest.
Sadiq Akbar
on 15 Oct 2020
Thank you very much for your 5th response. I saved your program as a function. Then all the 8 figures were opened and then I opened the 9th figure also. After that I opened your program and clicked the run button.But it gives me the following error:
>> change_figures_size
Not enough input arguments.
Error in change_figures_size (line 3)
figs = setdiff(figs, fig9)
>>
Ameer Hamza
on 15 Oct 2020
No, you cannot run it just like that. You need to pass the handle of 9th figure.
fig9 = openfig('9th_fig_file.fig');
change_figures_size(fig9)
Sadiq Akbar
on 15 Oct 2020
Indeed it worked. Thank you very much for your tireless efforts and cosistant support and help. May you live long and help others like this. Thank you once again.
Ameer Hamza
on 15 Oct 2020
You can post a new question and paste the link in the comment below. I will try to answer if possible.
Sadiq Akbar
on 15 Oct 2020
Ok thank you very much dear Ameer Hamza for your kind support and devoted help. May you live long happily.
Sadiq Akbar
on 15 Oct 2020
https://www.mathworks.com/matlabcentral/answers/615303-how-to-export-a-figure-into-ms-word
More Answers (0)
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)