How to get data multiple times from Matlab GUI without closing GUI each time
Show older comments
I am trying to design a system using MATLAB GUI, where I have to get two different inputs from user and then do processing with those inputs. For that I have placed a popupmenu which has values [1 2 3 4 5] from which user can select the first input, and second pop up menu which has values [6 7 8 9 10], from which user can select the second input. Then I have placed a pushbutton named Process,which will do the required processing when it is pressed. So,when I run the code and select the input1 from first popup menu and then select input2 from second popup menu and then select process button, the data is getting processed. But when I wish to change the input1 and input2 values by again selecting the data from popup menu1 and 2,it is showing error as deleted object.So, I have to close matlab GUI window and then again run the code. Is there any means of clearing the data after processing so that I don't need to close the GUI each time and rerun it?The code is attached :
function input_data1_Callback(hObject, eventdata, handles)
input_data1=get(handles.input_data1,'Value');
handles.input_data1=input_data1;
guidata(hObject,handles);
function input_data2_Callback(hObject, eventdata, handles)
input_data2=get(handles.input_data2,'Value');
handles.input_data2=input_data2;
guidata(hObject,handles);
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
input_data1=handles.input_data1;
input_data2=handles.input_data2;
out=input_data1+input_data2;
handles.out=input_data1+input_data2;
assignin('base','out',out);


3 Comments
Jon
on 11 Nov 2022
I would suggest implementing your GUI using MATLAB App Designer rather than Guide. Guide is obsolete and soon will no longer be included in future releases. https://www.mathworks.com/help/matlab/app-designer.html
Once you have done that, and assuming you still have a problem, please attach a working example of the code that demonstrates the problem so that we can help you debug it.
Jon
on 11 Nov 2022
Please attach example code with all needed files that demonstrates the problem. Also please copy and paste the entire error message that you receive when you run the code and any instructions for how to replicate the problem.
Image Analyst
on 12 Nov 2022
@Deepa Jayan your edit was no good. You still forgot to attach the .m and .mfig file. And obviously you didn't read my tutorial link below. We'll check back later for the files.
Answers (1)
Image Analyst
on 11 Nov 2022
0 votes
You're probably calling clear somewhere. Or you're overwriting a control handle with a property value so that it's no longer the handle to the control (popup or button). I'm sure it's easily fixed, however you forgot to attach your .fig file and .m file, probably because you skipped reading the Community Guidelines.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Once we have those files we can fix them quickly and post the corrected versions.
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!