how to know the dimension of a figure window and then draw my own according to same dimension
8 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
Ameer Hamza
2020-10-14
编辑:Ameer Hamza
2020-10-14
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 个评论
Sadiq Akbar
2020-10-14
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
2020-10-14
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
2020-10-14
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
2020-10-14
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
2020-10-14
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
2020-10-14
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
2020-10-15
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
2020-10-15
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
2020-10-15
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
2020-10-15
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
2020-10-15
You can post a new question and paste the link in the comment below. I will try to answer if possible.
Sadiq Akbar
2020-10-15
Ok thank you very much dear Ameer Hamza for your kind support and devoted help. May you live long happily.
Sadiq Akbar
2020-10-15
https://www.mathworks.com/matlabcentral/answers/615303-how-to-export-a-figure-into-ms-word
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)