How do I choose an input using a GUI/explorer window in a MATLAB program?
-
22-07-2019 - |
Question
I actually have 2 queries:
How do I display the data of a variable in a msgbox? In other words, if I have
dist=3765
at the end of my program and I want to display it in a msgbox, how do I do it?I want the user to select an input file (suppose an image) from a folder in my MATLAB program using an explorer window at runtime. How do I code that in MATLAB, or is there an existing function available for it?
Solution
You should check out these MathWorks blog posts (here and here) from Ken and Mike discussing all of the dialog boxes that you can use in MATLAB. The specific dialog boxes that address the needs listed in your question would be:
MSGBOX, which will display a message. You first have to create a string to use as a message. For example, if you have a variable
dist
that stores an integer value you want to display, you can do the following (using the function INT2STR):hMessage = msgbox(['dist = ' int2str(dist)]);
UIGETFILE, which opens a dialog box for selecting a file and returns the file name and path selected. For example, the following opens up a dialog box to select a MATLAB file (*.m, *.fig, *.mat, etc.) from the current directory:
[fileName,filePath] = uigetfile();