Running Scripts in the GUI
1 view (last 30 days)
Show older comments
Hello everyone,
i have made a .m file and im new to matlab, i want to use this .m in the GUI. This is i want to make: GUI with a pushbuttom1 and text beside it so if you write a text file name in there it will get you a function i have made already, after that i want all the data that i get in the matlab appear in a Listbox.
i made the design its easy but how to hyberlink that codes with the design i cant do it at all :(
i wish if there anyone could help thank you
0 Comments
Accepted Answer
Evan
on 14 Dec 2012
Edited: Evan
on 14 Dec 2012
Did you design your GUI using guide? That will make things much easier, especially if you're new to Matlab as you mention.
If the GUI is made in guide, an mfile will be generated once you save the GUI. After that, you would just need to put your code in the pushbutton's callback. I wouldn't think it would take a ton of code to do what you want, just something like this:
function pushbutton1_Callback(hObject, eventdata, handles) %button callback
func_name = get(handles.editbox1,'String'); %name you entered in edit box
myfun = str2func(func_name); %turn the string into a function handle
myfun_output = myfun;
%some formatting of myfun_output here perhaps, for readability and to
% convert it to a string.
set(handles.listbox1,'String',myfun_output) %your listbox
guidata(hObject,handles)
Your main question, though, just seemed to be about being able to call the function from within your GUI's mfile. To do that, all you should have to do is call the function from within the button's callback. Depending on the needed inputs to your function, things could get a little more complicated, but the calling one function from another and saving the output part is relatively simple.
0 Comments
More Answers (1)
See Also
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!