Access to Matlab Main Window position coordinates

Is there any way that I could access the MAIN MATLAB WINDOW (Matlab 7.9.0 (R2009b)) the same way I can access a figure ? With a handle ?
What I am trying to do is reposition the main window as part of a script.
For example I already have a script that will reposition and resize all my figures stacked in the middle of my screen, but I would like to access the main window and the script editor window as well.
So far the only information I can get is the Matrix size of the command window(about useless), which in my case is just some part of what I call the main window using.
get(0,'CommandWindowSize')
Thank you for the help.

 採用された回答

Kaustubha Govind
Kaustubha Govind 2011 年 3 月 15 日

4 投票

You could use the MATLAB Java API (see examples on the blog Undocumented MATLAB) to do this kind of thing:
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
desktopMainFrame = desktop.getMainFrame;
% Get desktop dimensions
desktopDims = desktopMainFrame.getSize;
desktopW = desktopDims.getWidth;
desktopH = desktopDims.getHeight;
% Resize desktop to half of original size
desktopMainFrame.setSize(desktopW/2,desktopH/2);
You can explore the other methods on the objects for more.
Use this with caution, however, because this API is undocumented, and may change in a future release. It may be best to protect your code with some version checking (older or newer versions may have different APIs).
I tried to do something similar with the Editor window by using:
editor = desktop.getGroupContainer('Editor');
But, I couldn't get the window to resize. You might be able to have something working by exploring further.
PS: I am using R2010b

7 件のコメント

Oleg Komarov
Oleg Komarov 2011 年 3 月 15 日
+1
Pete
Pete 2012 年 11 月 19 日
Excellent answer, very helpful.
Btw, for analogous process using the editor, the following works for me [R2012]:
container = desktop.getGroupContainer('Editor').getTopLevelAncestor
container.setSize ... etc.
Royi Avital
Royi Avital 2016 年 10 月 15 日
It seems not to work on MATLAB R2016a. Namely can't change the properties (Can see, but not change).
Walter Roberson
Walter Roberson 2016 年 10 月 15 日
Example:
container.setSize(java.awt.Dimension(1350,1100))
Royi Avital
Royi Avital 2016 年 10 月 16 日
編集済み: Royi Avital 2016 年 10 月 16 日
Hi Walter, It worked! Could you explain me why? What about setting all 4 parameters of the rectangle (Like 'Position' for figures)? Thank You.
Walter Roberson
Walter Roberson 2016 年 10 月 16 日
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
container = desktop.getGroupContainer('Editor').getTopLevelAncestor;
x = 200; y = 319; w = 952; h = 1077;
container.setLocation(java.awt.Point(x, y))
container.setSize(java.awt.Dimension(h, w))
The underlying java object does not use the [x, y, h, w] kind of Position settings: it has a location of the upper left corner (in pixels from the upper left corner), and it has a size, which is height and width.
"Why"... I do not know enough about Java to know why it does anything. Before I researched the answer for you, I had no idea how to set the dimensions or position. I took the easy route: I just searched the source code in one of the private methods.
Royi Avital
Royi Avital 2016 年 10 月 16 日
Fabulous!
Thank You.

サインインしてコメントする。

その他の回答 (2 件)

j dr
j dr 2011 年 3 月 16 日

0 投票

I guess this will have to do...
Maybe I shouldn't have accepted it tho
Jan
Jan 2016 年 10 月 16 日

0 投票

This tool bundles some functions to access the command window: FEX: CmdWinTool

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

質問済み:

2011 年 3 月 15 日

回答済み:

Jan
2016 年 10 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by