UI doesn't show buttongroups but doesn't give any error
이전 댓글 표시
Hello everyone, I am trying to dynamically create a UI with changing number of buttongroups and radiobuttons. However, when I run it nothing comes up in the uifigure. Can someone help me sorts this out? I am sharing the code.
% inputs to the function
TotalSong = 3;
TotalOptionNo = 5;
fig = uifigure();
for i = 1:TotalSong
y = 1-(1-0.7/TotalSong)*i/TotalSong
if y<0
y = 0;
end
bg(i).bg = uibuttongroup(fig,'Title',['Song' int2str(i)], 'Visible','off',...
'Position',[0 y 1 0.7/TotalSong],...
'Units', 'normalized');
for k = 1:TotalOptionNo
rb(k).(['bg' int2str(i)]) = uiradiobutton(bg(i).bg,...
'Value', 0,...
'Text', int2str(k),...
'Position',[(1-0.3)*k/TotalOptionNo 0 0.1 0.5]);
end
bg(i).bg.Visible = 'on';
end
채택된 답변
추가 답변 (1개)
The problem you're running into is just the order in which you set Units and Position:
bg(i).bg = uibuttongroup(fig,'Title',['Song' int2str(i)], 'Visible','off',...
'Position',[0 y 1 0.7/TotalSong],...
'Units', 'normalized');
This sets the Position in the default Units of uibuttongroup (which are pixels when that uibuggongroup is in a uifigure) and then sets the Units to normalized. So the buttongroups exist in your figure, but they are really tiny (hence, no error).
Swapping to setting the Units first should do the trick:
bg(i).bg = uibuttongroup(fig,'Title',['Song' int2str(i)], 'Visible','off',...
'Units', 'normalized', ...
'Position',[0 y 1 0.7/TotalSong]);
카테고리
도움말 센터 및 File Exchange에서 Develop Apps Programmatically에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!