What could be causing unexpected positioning of a GUI in Matlab?

  • MATLAB
  • Thread starter boolean_logic
  • Start date
  • Tags
    Gui Matlab
In summary, the individual has been trying different methods to reposition their GUI within the OpeningFcn. They first tried using the code h=get(handles.figure1,'Position'); set(0,'Units','normalized') S = get(0,'screensize'); width = h(3); height=h(4); x = (S(3) - width)/2; y = (S(4) - height)/2; set(handles.figure1,'Position',[x,y,width,height]); However, this resulted in the GUI being positioned in an unexpected location. Even when they tried replacing set(handles.figure1,'Position',[x,y,width,height]) with set(handles.figure1,'Position',S), the problem persisted. The individual then found that the
  • #1
boolean_logic
2
0
I have been trying the following to reposition my GUI (within the OpeningFcn):

h=get(handles.figure1,'Position');
set(0,'Units','normalized')
S = get(0,'screensize');
width = h(3);
height=h(4);
x = (S(3) - width)/2;
y = (S(4) - height)/2;
set(handles.figure1,'Position',[x,y,width,height]);

However this results in the Gui being position in an unexpected position. I am not sure why this is but the problem persists even if I replace set(handles.figure1,'Position',[x,y,width,height]) with set(handles.figure1,'Position',S) - I expected this change in code to result in a full screen gui however the position was offset (the width and height appeared correct though).
 
Physics news on Phys.org
  • #2
The only way I have been able to consistently reposition the GUI is by using the following code:h=get(handles.figure1,'Position');set(0,'Units','pixels')S = get(0,'screensize');width = h(3);height=h(4);x = (S(3) - width)/2;y = (S(4) - height)/2;set(handles.figure1,'Position',[x,y,width,height]);Does anyone know why the first set of code may not be working as expected? Is there something I am missing? Any help would be much appreciated.
 

Related to What could be causing unexpected positioning of a GUI in Matlab?

What is the "Fix Matlab GUI Resize Issue"?

The "Fix Matlab GUI Resize Issue" is a common problem encountered by users of the Matlab software. It refers to the issue of the GUI (Graphical User Interface) not resizing correctly when the user changes the size of the window or their screen resolution.

How does the "Fix Matlab GUI Resize Issue" affect users?

The "Fix Matlab GUI Resize Issue" can be frustrating for users as it can make it difficult to view and interact with the GUI elements, resulting in a poor user experience. It can also make it challenging to create responsive and visually appealing GUIs.

What causes the "Fix Matlab GUI Resize Issue"?

The "Fix Matlab GUI Resize Issue" can be caused by a variety of factors, including the use of incorrect or outdated code, improper handling of units and positions, or conflicts with other functions or toolboxes.

How can the "Fix Matlab GUI Resize Issue" be resolved?

The "Fix Matlab GUI Resize Issue" can be resolved by carefully reviewing and modifying the code to ensure proper handling of units and positions. It may also require updating the code to be compatible with the latest version of Matlab or resolving conflicts with other functions or toolboxes.

Are there any tips for avoiding the "Fix Matlab GUI Resize Issue" in the future?

To avoid the "Fix Matlab GUI Resize Issue" in the future, make sure to use correct and up-to-date code when creating GUIs, and test the GUI on different screen resolutions and window sizes. Additionally, regularly updating your Matlab software and keeping track of any changes or updates to functions and toolboxes can help prevent this issue from occurring.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
619
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top