Using pushbutton to load an .m file in GUI
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Laila Buncab
el 27 de Mayo de 2015
Comentada: Walter Roberson
el 27 de Mayo de 2015
I'd like for a pushbutton to open a .m file(when you run the .m file, a .fig file appears). How do I do that?
I actually don't know anything about MATLAB, this was just my officemate's work passed on to me.
0 comentarios
Respuesta aceptada
Joseph Cheng
el 27 de Mayo de 2015
you would first create a pushbutton in either GUIDE or manually using uicontrol. Then you would change the callback function to run a function that uses uigetfile() and the run() functions. see my example:
function test() %main function
%create the button and adjust the callback
btn = uicontrol('Style', 'pushbutton', 'String', 'Clear',...
'Position', [20 20 50 20],...
'Callback', @runfile);
%what the button does when clicked
function runfile(hobject,event)
[file folder]=uigetfile('*.m'); %prompt user to select mfile
run(fullfile(folder,file)); %fun the m-file.
4 comentarios
Walter Roberson
el 27 de Mayo de 2015
If you want the button in a different place or different size then change the parameter you are passing for Position.
The Warning is a warning and does not affect what comes after.
run() is able to find the directory you specified. However, there is no performancegraph.m there. Check for spelling mistakes, and check in case the actual file name has uppercase in some characters.
Más respuestas (0)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
