可以在MATLAB命令行窗口中输入help guide,然后点击"guide 的参考页",进去后找到"Create a Simple App Using GUIDE"并点击,里面有详细教程。跟着教程走,有以下一些注意事项:
1、 handles.peaks=peaks(35); handles.brane=membrane; [x,y] = meshgrid(-8:.5:8); r = sqrt(x.2+y.2) + eps; sinc = sin®./r; handles.sin = sinc; % Set the current data value. handles.current_data = handles.peaks; surf(handles.current_data) % Choose default command line output for simple_gui handles.output = hObject; 里面的“handles.peaks”、“handles.brane”、“handles.sin”,handles.后的字符是可以自己任意修改的,如“handles.peaks”可改为”handles.ppppp“. 该处相当于创建一个类成员并赋值。 2、 % Determine the selected data set. str = get(hObject, ‘String’); val = get(hObject,‘Value’); % Set current data to the selected data set. switch str{val} case ‘peaks’ % User selects peaks. handles.current_data = handles.peaks; case ‘membrane’ % User selects membrane. handles.current_data = handles.membrane; case ‘sinc’ % User selects sinc. handles.current_data = handles.sinc; end % Save the handles structure. guidata(hObject,handles) case后的字符可跟着String的值更改为中文,,同理后面的handles.peaks也跟着之前更改的字符更改。如: % Determine the selected data set. str = get(hObject, ‘String’); val = get(hObject,‘Value’); % Set current data to the selected data set. switch str{val} case ‘高斯’ % User selects peaks. handles.current_data = handles.ppppp; case ‘不知啥’ % User selects membrane. handles.current_data = handles.brane; case ‘正弦’ % User selects sinc. handles.current_data = handles.sin; end % Save the handles structure. guidata(hObject,handles) 该处将当前调用的类成员的值赋给handles.current_data,然后在后面的普通按钮调用。如: function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Display surf plot of the currently selected data. surf(handles.current_data); %该处调用了当前调用的类成员的值 图例: