在matlab GUI中创建一个按钮数组

Ehs*_*san 1 matlab user-interface matlab-guide

有没有办法制作一个对象数组(按钮,静态文本,字段等),其大小由用户在matlab gui中给出?

例如,用户在字段中键入12,然后创建12个按钮.

PS mathworks.com不允许我访问它的页面.一些幼稚的政治事物:请在这里回答.感谢名单!

Thi*_*jsW 5

你可以尝试这样的事情:

N = input('How many buttons?   ');

hFig = figure;

hGroup = uibuttongroup('Units','Normalized','Position',[0 0 1 1]);

for i = 1:N
    hText(i) = uicontrol('Style','Text','String',['Variable' num2str(i)],...
        'Parent',hGroup,'Units','normalized','Position',[0 1-i/(N+1) 1/2 1/(N+1)],...
        'BackgroundColor','white');
    hInput(i) = uicontrol('Style','edit',...
        'Parent',hGroup,'Units','normalized','Position',[1/2 1-i/(N+1) 1/2 1/(N+1)],...
        'BackgroundColor','white');
end

hButton = uicontrol('Style','pushbutton','Parent',hGroup,'Units','normalized',...
    'String','Go!','Position',[0 0 1 1/(N+1)],'Callback',{});
Run Code Online (Sandbox Code Playgroud)

当然,您可以使用位置等.您可以将uibuttongroup输入字段显示在任何位置.