MATLAB新手-在弹出菜单中添加元素 [英] MATLAB newbie - add element to pop-up menu

查看:114
本文介绍了MATLAB新手-在弹出菜单中添加元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将元素添加到我的弹出菜单中,以便用户在文本字段中编写该元素,因此我对Matlab还是陌生的,因此,非常感谢您进行任何解释,我知道它与按钮中的回调有关,但是我不知道知道该怎么做..

i want to add element to my pop-up menu that user write it in a text field , i'm new to matlab so any explanation is very appreciated , i know it's about a callback in the pushbutton but i don't know how to do it exactly..

到目前为止,我的gui:

My gui so far :

到目前为止我的代码:

function varargout = popupmenu(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @popupmenu_OpeningFcn, ...
                   'gui_OutputFcn',  @popupmenu_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end


function popupmenu_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;


guidata(hObject, handles);





function varargout = popupmenu_OutputFcn(hObject, eventdata, handles) 

varargout{1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)


function edit1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function popupmenu1_Callback(hObject, eventdata, handles)


function popupmenu1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function pushbutton1_Callback(hObject, eventdata, handles)

推荐答案

pushbutton1_Callback中,您可以添加:

new_item=get(handles.edit_1,'string') % to get the string from the edit box
tmp=get(handles.popupmenu1,'string') % to get the actual list of items in the popup menu
tmp{end+1}=new_item % to add the string
set(handles.popupmenu1,'string',tmp) % to update the popup menu items

这篇关于MATLAB新手-在弹出菜单中添加元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆