声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2328|回复: 8

[GUI界面] 关于popup menu的调用函数的问题

[复制链接]
发表于 2007-7-24 19:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
那个switch的 代码该怎么样写?
图中该设置什么?
多谢大家了

% --- Executes on selection change in sel.
function sel_Callback(hObject, eventdata, handles)
% hObject    handle to sel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns sel contents as cell array
%        contents{get(hObject,'Value')} returns selected item from sel
switch sel_data
    case 1
        haha=str2num(get(handles.input,'string'))
    case 2
        hehe=str2num(get(handles.input,'string'))
    case 3
        huhu=str2num(get(handles.input,'string'))
    otherwise
        hoho=str2num(get(handles.input,'string'))
end



% --- Executes during object creation, after setting all properties.
function sel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

[ 本帖最后由 HolySaint 于 2007-7-24 19:29 编辑 ]
4900.PNG
回复
分享到:

使用道具 举报

 楼主| 发表于 2007-7-24 19:32 | 显示全部楼层
错误如下

??? Undefined function or variable 'sel_data'.

Error in ==> test>sel_Callback at 84
switch sel_data

Error in ==> gui_mainfcn at 75
        feval(varargin{:});

Error in ==> test at 42
    gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uicontrol Callback.


哪一项改设成switch的参数呢?

我是想达到这个要求:
分别给四个变量赋值
另外,如果赋一个值后删除edit的内容用clc edit可以吗?
发表于 2007-7-24 19:46 | 显示全部楼层
看gui设计的精华帖
 楼主| 发表于 2007-7-24 20:32 | 显示全部楼层
自己搞定了一部分
seldata = get(handles.sel, 'Value');
switch seldata
    case 1
        haha=str2num(get(handles.input,'string'))
    case 2
        hehe=str2num(get(handles.input,'string'))
    case 3
        huhu=str2num(get(handles.input,'string'))
    otherwise
        hoho=str2num(get(handles.input,'string'))
end

但是不能清楚edit的内容
有类似的例子吗?用popup menu的例子?
 楼主| 发表于 2007-7-24 20:42 | 显示全部楼层
http://forum.vibunion.com/forum/ ... 7%C3%E6%B1%E0%B3%CC
这页的东西我也下不了啊
版主能帮忙传到邮箱里吗?
多谢了啊BIT20040605@gmail.com
发表于 2007-7-24 22:46 | 显示全部楼层

回复 #5 HolySaint 的帖子

程序调试遇到错误请参考
常见的程序出错问题整理
参考例子请到这个帖子下载
http://forum.vibunion.com/forum/vi ... 6amp%3Btypeid%3D164

[ 本帖最后由 花如月 于 2007-7-24 22:48 编辑 ]
 楼主| 发表于 2007-7-25 01:10 | 显示全部楼层

回复 #6 花如月 的帖子

多谢版主大大:handshake
 楼主| 发表于 2007-7-25 12:25 | 显示全部楼层
还有一个问题

就是我不能保存输入的数据

弹出菜单下选中a输入12

根据我定义的变量输出a=12

但是以后用a的时候还是会出错

说是没定义

怎么把数据输入後保存呢?
发表于 2007-7-25 12:28 | 显示全部楼层
请看eight版主的关于gui的精华帖子
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-10-3 00:33 , Processed in 0.071632 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表