Using Push Button to Export a String to an Edit Textbox (GUI)
5 次查看(过去 30 天)
显示 更早的评论
Hello all, as simply as possible, how would you export a string to an Edit Textbox so it can be displayed when the GUI is run?
Would you use a combination of setappdata, getappdata, sprintf()? I'm new to GUI and would really like a good universal "recipe" or method that can be easily adapted for other similar purposes (say, export cell arrays from a listbox to an axes1 graph, etc.).
For example, my string is "Name" here below in my Push Button Callback function :
function pushbutton4_Callback(hObject, eventdata, handles)
Name = 'Thomas';
setappdata(handles.figure1, 'Name', Name); %Storing my string "Name" in my UI figure1.
And I would like to export this name and display it into my Edit Textbox (Callback function here) :
function edit1_Callback(hObject, eventdata, handles)
Name = getappdata(handles.figure1 , 'Name'); %Retrieving my string "Name"
set(handles.edit1,'String', Name); % Displaying my string "Name" into my Edit Textbox.
I'm probably getting this all wrong. I'm not sure what to use to display my string "Name". It should look like this button on the right and the Edit textbox on the left :
Thanks for the support!
3 个评论
Rik
2019-6-12
You mention in one of your code comment that you have a UI figure. That suggests you're using AppDesigner (which uses uifigure), while the rest of your code implies you're using GUIDE. If you are using the latter I have some advice on how to stop using it. It has an outdated structure with a lot of bloat that is likely reducing your efficiency (e.g. it still warns that eventdata is reserved for a future release, despite it being in use for years).
My small guide to avoid GUIDE:
- Make a figure (with f=figure;) and look into the doc for figure which properties you want to turn off (you probably want to set Menu and Toolbar to 'none')
- Create buttons and axes and everything you need with functions like uicontrol and axes. Save the handles to each element to fields of a struct (like handles.mybutton=uicontrol(___);)
- When you've finished loading all data (and saving it to fields of your handles struct), and creating all the buttons, save your handles struct to the guidata of your figure like this guidata(handles.f,handles);. (You can also use getappdata and setappdata)
- You can set the Callback property of many objects. If you do, use a function name with an @ in front, or a char array that can be evaluated to valid code. (like @MyFunction or 'disp(''you pushed the button'')')
- Callback functions will be called with two arguments: the first is a handle to the callback object, the second is eventdata that may contain special information. To get access to your data, just use handles=guidata(gcbo);. You can replace the gcbo function with the name of the first input to your callback function if you prefer.
- More information about callbacks can be found in multiple places in the doc, for example here.
I will leave the answer section for G A.
采纳的回答
G A
2019-6-12
set(handles.edit1,'String', Name); % Displaying my string "Name" into my Edit Textbox.
Put this line in your pushbutton4_Callback fuction
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Maintain or Transition figure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!