hello.. i have a program in m-file ...n i want to run that file when gui pushbutton is clicked..and the output of that m-file should be displayed in edit box..... plz tell me the solution ..... i m doing m.tech thesis on matlab gui .......

2 views (last 30 days)
hello.. i have a program in m-file ...n i want to run that file when gui pushbutton is clicked..and the output of that m-file should be displayed in edit box..... plz tell me the solution ..... i m doing m.tech thesis on matlab gui .......

Accepted Answer

Geoff Hayes
Geoff Hayes on 19 Apr 2014
Hi monu,
I think what you want to do is invoke your program (in the m-file) from a callback that is associated with your button. Presumably you are using GUIDE to develop your GUI with buttons and other widgets. Within the *.fig (GUIDE) layout for your GUI, double-click on the button that is to call your program. Observe the that Inspector: uicontrol(pushbutton…) window appears. Look for the Callback item and press the edit button (pencil on paper image) that is beside it. This should bring up your GUI *.m file with code similar to the following:
% --- Executes on button press in pushbutton1.
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)
Note that pushbutton1 is the name or Tag (see inspector window for Tag) for this button widget and so may be different from the tag assigned to your widget. This is just an empty function that (currently) does nothing but will get called whenever the user pushes the button on the GUI. It is within this function (pushbutton1_Callback) that you will add some code to invoke your program (in the other m-file):
% call your other program here
[results] = otherProgram();
Now that you have called your other program and the results have been returned, these results should be displayed in an edit box on your GUI. Like this button whose Tag is 'pushbutton1' (in my example) the edit control will have its own unique Tag say "edit1". (Note that you can change these tag names to something more obvious given the nature of the button, edit control, etc.) The tag acts as an identifier within the list of handles for the GUI. So you can use the tag to get the control and update its contents like:
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)
% call your other program here
[results] = otherProgram();
% assume that results is a number of some kind (for this example)
% update edit1 control with results
set(handles.edit1,'String',num2str(results));
% in the above we use the "handles" input to this function (see callback signature)
% to grab the control (given by the Tag "edit1") that we wish to update;
% since the edit control is populated with a string of characters, we set its 'String'
% property to the results (that have been converted to a string)
Hope this helps!
geoff
  3 Comments
monu
monu on 19 Apr 2014
it shows error in results let me tell u the m-file name i.e pso_GCVmax .m ....and the edit box tagged as cost and the pushbutton named as cost of generation.......could u plz help me...
Geoff Hayes
Geoff Hayes on 19 Apr 2014
Could you please post the body of your callback? What is the error?
Please make sure that your widget Tags are single words only (no spaces) like:
cost costOfGeneration

Sign in to comment.

More Answers (1)

monu
monu on 20 Apr 2014
function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% call your other program here

Categories

Find more on Migrate GUIDE Apps 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!