Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Access to Matlab Main Window position coordinates

Asked by j dr

j dr (view profile)

on 15 Mar 2011

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.


Thank you for the help.


j dr

j dr (view profile)


No products are associated with this question.

2 Answers

Answer by Kaustubha Govind

Kaustubha Govind (view profile)

on 15 Mar 2011
Accepted answer

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

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


Oleg Komarov

Oleg Komarov (view profile)

on 15 Mar 2011



Pete (view profile)

on 19 Nov 2012

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.
Kaustubha Govind

Kaustubha Govind (view profile)

Answer by j dr

j dr (view profile)

on 16 Mar 2011

I guess this will have to do...

Maybe I shouldn't have accepted it tho

1 Comment

Oleg Komarov

Oleg Komarov (view profile)

on 16 Mar 2011

Why not?

j dr

j dr (view profile)

Contact us