In the GUI in MATLAB, how to change the input of a filename in a function for it to be read
1 次查看(过去 30 天)
显示 更早的评论
I have a question. I’m trying to build a Graphical User Interface (GUI). I wish take a file and from there automatically read the file. In doing so, I manage to get the file by using the coding below.
[filename pathname] = uigetfile({'*.txt'},'File Selector');
fullpathname = strcat(pathname, filename);
text = fileread(fullpathname); % Reading information inside a file
set(handles.text2, 'String', fullpathname); % Showing FullPathName
set(handles.text3, 'String', text); % Showing information
The file is in the form such as below :-
aae20110806dmin.min
her20110724dmin.min
iqa20110724dmin.min
When I’m using the coding above, the file can be obtain. It is show in the command window.
The output of the coding is a periodogram being produce. In order for the periodogram to be produce, I have to manually change the file name from the function. The function is such below.
[UT1m,MagDataIAGA] = ReadIAGA1m('fcc20110724dmin.min');
I would like to ask is there a method where I can from the GUI take a file such file
‘ aae20110806dmin.min ‘, and it would be change in the function of the
[UT1m,MagDataIAGA] = ReadIAGA1m('aae20110806dmin.min');
And then when I press the push button in GUI, the periodogram will produce the file of 'aae20110806dmin.min'.
0 个评论
采纳的回答
Mara
2020-6-18
From what I understand, your the name 'aae20110806dmin.min' is saved as a string variable called filename.
if you want to use the variable filename in the function that executes when you push the push button, you have to set the variable as a global variable.
Not sure if I understood you right but hope it helps!
% my uigetfile function
global filename
%my pushbutton function
global filename
[UT1m,MagDataIAGA] = ReadIAGA1m(filename);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!