Matlab 循环GUI功能

Matlab 循环GUI功能,matlab,loops,matlab-guide,Matlab,Loops,Matlab Guide,我只是想知道是否有可能高效地循环GUI功能 function Menu1_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hO

我只是想知道是否有可能高效地循环GUI功能

function Menu1_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
    function Menu2_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
    function Menu3_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
    % if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
    function Menu4_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
目前我有:

HandleNames = {'Menu1','Menu2','Menu3','Menu4'};
for d = 1:4   
    eval('function (HandleNames{d})_Callback(~, ~, ~)');
    eval('function (HandleNames{d})_CreateFcn(hObject, ~, ~)');
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
end

但是我很清楚eval函数不是一个好的实践,它在命令窗口中抛出了一些错误,但是仍然像以前一样工作。干杯,有没有更优雅的方式来做这件事,或者这只是我必须处理的一件事。

啊,我知道你在用指南。对于简单的、一次性的GUI来说,这是一个很好的工具,但是一旦你尝试做任何整洁的事情,你就会把它推过它的极限。幸运的是,有更好的方法。您需要使用这些函数部分或全部构建GUI。因此,对于您感兴趣的特定任务,请尝试以下方法:

menuSet = {'Hi', 'This is a menu', 'and another', 'neat, huh?'};
for menuIndex = 1:numel(menuSet)
    menuHandle = uimenu(fh,'Label', menuSet{menuIndex);
    % You can use menuHandle here, to manipulate any of the menus
    % properties, or add a sub-menu!
end
您还可以添加子菜单,分配上下文,以及所有其他有趣的事情。我知道这是一个学习曲线,但如果你打算将MATLAB用于任何严肃的GUI应用程序,我强烈建议你学习所有编程GUI函数,其中
uimenu
只是其中之一。祝你好运