Tejashree
Tejashree

Reputation: 51

Open file explorer using matlab gui pushbutton

I want to create a MATLAB gui where I can open file explorer using a pushbutton and select a file for further processing. How can I do that?

Also I want to know how to assign .m function files to the pushbuttons. I tried putting functionname.m file in callback of the pushbutton. But it didn't work.

Please help me with both doubts.

Upvotes: 0

Views: 697

Answers (1)

Suever
Suever

Reputation: 65440

You'll need to write a callback function to launch the file selection dialog (uigetfile)

set(hbutton, 'Callback', @mycallback)

function mycallback(src, evnt)
    [fname, pname] = uigetfile();

    filepath = fullfile(pname, fname);

    % Do something with filepath

end

In general if you want to call any .m file from within a callback, you'll want to wrap the call to it in an anonymous function

set(hbutton, 'Callback', @(src,evnt)functionname())

Upvotes: 1

Related Questions