Aligning controls in a Matlab script
8 次查看(过去 30 天)
显示 更早的评论
I have edit fields in a Matlab script for user input of numerical parameters. How do I align the input field boxes, for example, so that they have the same end position on the right, when code is hidden? In the example below, I want the boxed fields to be aligned right, rather than having the text aligned left, which causes the boxes to be staggered. This is a simple Matlab script, with inserted edit fields. The text is the "label" in the configuration of the control. Many thanks in advance!
2 个评论
Angelo Yeo
2023-12-18
In my R2023b (Update 4), the edit fields are automatically aligned when codes are hidden. Can you specify the reproduction steps for your issue? Or you can attach the live script with the issue.
回答(1 个)
Pratyush
2023-12-18
Hi Peter,
I understand that you want to align the edit fields so that they have the same end position on the right.
The 'Position' property is a four-element vector [left bottom width height] that defines the size and position of the control. You can refer to the following link for more details: https://in.mathworks.com/help/matlab/ref/matlab.ui.figureappd-properties.html#d126e1937327
You need to ensure that the sum of the 'left' and 'width' properties is the same for all edit fields.
Here's an example of how you might do this programmatically:
% Define the width and right edge position of the edit fields
editFieldWidth = 100; % Width of the edit fields
rightEdgePosition = 300; % Position of the right edge of the edit fields
% Calculate the 'left' position for each edit field so that the right ends align
editField1Left = rightEdgePosition - editFieldWidth;
editField2Left = rightEdgePosition - editFieldWidth;
% ... do this for each edit field
% Create the edit fields with aligned right ends
editField1 = uicontrol('Style', 'edit', 'Position', [editField1Left 200 editFieldWidth 20]);
editField2 = uicontrol('Style', 'edit', 'Position', [editField2Left 170 editFieldWidth 20]);
% ... create more edit fields as needed
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!