2017-06-21 22 views
0

入力引数に応じてGUIを作成できますか? たとえば、my_gui(n)を使用してGUIを呼びたいと思います。GUIには、スタイル 'pushbutton'のUIコントロールが1つずつ表示され、それぞれのプッシュボタンには別のコールバックがあります。一方、nは1から20の任意のノーベルになります。 これは何とかevalを使用していますか? これを行う方法を知っている人はいますか?入力引数に応じてGUIを作成する

例えば、その可能。もちろん、あなたの努力のおかげで

ラファエル

答えて

1

function myGui(n) 
    if nargin == 0; n = randi(20); end 
    if n > 20 || n < 1 
    error ('myGui:n', 'The input parameter "n" (%i) is outwith the allowed range (0 to 20)', n); 
    end 
    % create the parent figure 
    hFig = figure; 
    % create the positions 
    locations = linspace (0.9, 0.1, n); 
    % loop for n to create them, in this example the callback displays the number of the button pushed. 
    % The buttons have a fixed height of 0.05 (normalized). 
    for ii=1:n 
    uicontrol ('parent', hFig, 'style', 'push', 'Units', 'normalized', 'Position', [0.1 locations(ii) 0.5 0.05], 'String', num2str(ii), 'Callback', @(a,b)fprintf ('Pushed %i\n', ii)); 
    end 
end 
+0

うわー。これは迅速かつ正確でした。おかげで多く、これは素晴らしい作品 – Rafael

関連する問題