Matlab界面设计入门

1.文本编辑框+按钮
数据传递
pushbutton的callback代码:

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)
str=get(handles.edit1,'String');
set(handles.edit2,'String',str);

2.滚动条显示值
滚动条同步显示
滚动条后台callback代码(实践由滚动条产生触发):

function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
var=get(handles.slider1,'value');%value 属性哦
set(handles.edit1,'String',num2str(var));

3.单选框+复选框+togglebutton简单示例
切换现实上下限的值
三个控件的后台callback:

function rb_Callback(hObject, eventdata, handles)
% hObject    handle to rb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb
var=get(handles.rb,'value');
set(handles.edit1,'string',num2str(var));
% --- Executes on button press in ck.
function ck_Callback(hObject, eventdata, handles)
% hObject    handle to ck (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
var=get(handles.ck,'value');
set(handles.edit2,'string',num2str(var));
% Hint: get(hObject,'Value') returns toggle state of ck


% --- Executes on button press in tb.
function tb_Callback(hObject, eventdata, handles)
% hObject    handle to tb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of tb
var=get(handles.tb,'value');
set(handles.edit3,'string',num2str(var));

4.选择描绘不同三角函数曲线
buttonGroup的使用
将三个radio button放在一个button group中。
buttonGroup的后台SelectionChangeFcn:

function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%   EventName: string 'SelectionChanged' (read only)
%   OldValue: handle of the previously selected object or empty if none was selected
%   NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
x=0:0.01:2*pi;%x轴的范围0-2pi
current_Obj=get(eventdata.NewValue,'Tag');
axes(handles.axes1);
switch current_Obj
    case 'rb1'
      y=sin(x);
      plot(x,y);
    case 'rb2'
        y=cos(x);
        plot(x,y);
    case 'rb3'
        y=sin(x)+cos(x);
        plot(x,y);


end

5.下拉选择功能菜单
下拉框选择函数功能
pop up menu的callback代码:

function ppm_Callback(hObject, eventdata, handles)
% hObject    handle to ppm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns ppm contents as cell array
%        contents{get(hObject,'Value')} returns selected item from ppm
var=get(handles.ppm,'value');
x=0:0.01:2*pi;
axes(handles.axes1);
switch var
    case 1
        y=sin(x);
        plot(x,y);
    case 2
        y=cos(x);
        plot(x,y);
    case 3
        y=sin(x)+cos(x);
        plot(x,y);
end
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值