以编程方式在UIPanel中对齐轴处理 - Matlab

时间:2015-10-24 12:27:55

标签: matlab uicontrol

我在axes_h内调整uipanel句柄时遇到问题。我希望能够为我的情节提供一个特定的尺寸,然后将其置于面板中间,然后希望随后将我的uipanel与我的身材对齐。我查看了文档,示例仅在uicontrol内对齐并分发figure个按钮。

这是我的代码:

%% create figure
fig_h = figure;
set(fig_h, 'Position', [100, 100, 1049, 895]);

%% create empty scatter plot within a panel
e_panel_position = [0.1 0.4 0.4 0.5];
e_panel_h = uipanel('Parent', fig_h, 'Title','Emotion','FontSize',12,'BackgroundColor','white','Position',e_panel_position);

axes_position = [0 0 0.7 0.8];
axes_h = axes('Parent', e_panel_h, 'Position', axes_position);
scatter_h = scatter(axes_h, [],[], 'MarkerEdgeColor',[0 .5 .5], 'MarkerFaceColor',[0 .7 .7],'LineWidth',1.5);
axis(axes_h, [-4 4 -4 4]);
align(axes_h, 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle');

编辑:

我正在努力使用align函数获得两个静态文本框和一个滑块以直线对齐。我希望第一个文本框位于滑块前面,第二个文本框位于滑块的另一侧,如下所示:

slider

然后我希望能够从对齐对象中取出一个手柄,然后执行“对齐”的定心方法。以下建议将所有三个项目作为一个集体小组。图像说明了这一点,但这非常繁琐,因为我是手动完成的。但是,我需要在更多uipanel个框中为更多滑块执行此操作,因此我认为这将是一种更快捷的方法。

这是我的代码:

%% create environment slider and text with panel
env_panel_position = [0.1 0.33 0.4 0.1];
env_panel_h = uipanel('Parent', fig_h, 'Title','Environment','FontSize',12,'BackgroundColor','white','Position',env_panel_position);

dark_text_position = [0 0 0.1 0.3];
dry_text_h = uicontrol('Parent', env_panel_h, 'Style', 'text', 'units', 'normalized', 'position', dark_text_position, 'String', 'dark');

dark_light_slider_position = [0 0 0.7 0.1];
dark_light_slider_h = uicontrol('Parent', env_panel_h, 'Style', 'slider', 'units', 'normalized', 'position', dark_light_slider_position);

wet_text_position = [0 0 0.1 0.3];
wet_text_h = uicontrol('Parent', env_panel_h, 'Style', 'text', 'units', 'normalized', 'position', wet_text_position, 'String', 'Light');

align_h = align([dry_text_h dark_light_slider_h wet_text_h], 'Distribute', 'Middle');

1 个答案:

答案 0 :(得分:1)

align功能位置多个对象,因此它们排成一行。要将图形对象置于其容器中心,您只需要以normalized单位给它正确的位置,这是您正在创建的对象的默认位置。

您的定义axes_position = [0 0 0.7 0.8];表示axes_h的宽度为uipanel的70%,高度的80%。要使它居中,您只需要将左下角坐标设置为横向的15%和容器的10%:

axes_position = [0.15 0.1 0.7 0.8];

同样适用于uipanel的定位:

e_panel_position = [0.3 0.25 0.4 0.5];
相关问题