Passing Data Between GUI and .m Script
32 views (last 30 days)
I'm new to MATLAB and don't yet have a full understanding of GUIDE. I wrote a .m script that gathers data from text files, where the only input is the folder path containing the files. I would like to make a GUI where the folder path can be entered into a text box and then passed to the .m script. So I am wondering how to pass variables between the GUI and my .m script. Thanks in advance!
Volkan Kandemir on 17 May 2013
It is better not to use GUIDE. Developing a GUI with a m file is not so hard. You can use GLOBAL variable to transfer and store the data.
'OuterPosition',[0.2 0.3 0.6 0.7],...
'String','Write a note for text box',...
'Position', [0 0.7 0.5 0.3],...
'String','Click Me to transfer string of text box to me',...
'Position', [0.5 0.7 0.5 0.3],...
Image Analyst on 17 May 2013
"It is better not to use GUIDE." is not fact, and not my opinion. It's your opinion, and that's fine, but look at all those tedious parameters you have to code in manually if you do not use the GUI development tools available to you. Would someone new to MATLAB somehow know they have to set the 'Style' property or how to set the 'Callback' property? I don't have to worry about any of those, or if I do it's in a nice interactive GUI. Here are some tutorials to "guide" you through the process. That said, if you really want to "roll your own" you can look at this: http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples. Or better, check out MAGIC ( http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component) for a GUIDE-based framework that makes it easy.
Here's just the quick answer that directly answers your question:
% Browse for the file. Change starting folder as necessary.
folder = 'C:\Program Files\MATLAB\R2010b\toolbox\images\imdemos';
if ~exist(folder, 'dir')
folder = pwd;
fileSpecification = [folder '/*.*'];
% Ask user to specify the file.
[baseFileName, folder] = uigetfile(fileSpecification, 'Specify a file');
if baseFileName == 0
% Build up the full file name.
fullFileName = fullfile(folder, baseFileName);