2014-05-11 1 views
0

GUI 기능을 효율적으로 루핑 할 수 있는지 알고 싶습니다.루핑 GUI 기능

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 함수는 좋은 방법이 아니고, 명령 창에서 일부 오류를 던지고 있지만 여전히 이전처럼 작동하고 있는지 잘 알고 : 순간

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 

나는 있습니다. 이것을 할 수있는보다 우아한 방법이있을 것인가, 아니면 내가 다뤄야 만하는 것인가, 환호.

답변

1

아, GUIDE를 사용하고 있습니다. 간단하고도 손쉽게 GUI를 처리 할 수있는 훌륭한 도구이지만 일단 깔끔한 작업을 시도하면 한계를 넘어서게됩니다. 다행히도 더 좋은 방법이 있습니다. programmatic 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 

또한 하위 메뉴를 추가 할 수 있으며 컨텍스트를 할당하고 다른 흥미로운 것들 모든 종류의. 학습 곡선이 있다는 것을 알고 있지만 심각한 GUI 응용 프로그램에 MATLAB을 사용할 계획이라면 모든 프로그래밍 GUI 기능을 익히는 것이 좋습니다. 그 중 uimenu은 하나뿐입니다. 행운을 빕니다!