【发布时间】:2015-10-24 12:27:55
【问题描述】:
在uipanel 中对齐axes_h 句柄时遇到问题。我希望能够给我的图一个特定的大小,然后将它放在面板的中间,然后希望随后将我的uipanel 与我的数字对齐。我查看了文档,该示例仅在 figure 中对齐和分发 uicontrol 按钮。
这是我的代码:
%% 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 函数让两个静态文本框和一个滑块在一条直线上对齐。我希望第一个文本框位于滑块的前面,第二个文本框位于滑块的另一侧,如下所示:
然后我希望能够从对齐对象中获取句柄并执行“Will”在下面建议的居中方法,以将所有三个项目作为一个集合组居中。这张图片说明了这一点,但这样做非常繁琐,因为我是手动完成的。但是,我需要为更多 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');
【问题讨论】: