[App designer] Update text area or edit field with uigetfile (filename)
14 views (last 30 days)
Show older comments
I have a simple code to call a file using uigetfile
And I would like to show the selected filename in the TextArea or EditField.
So far I've tried this way,
but seems to me that the TextArea or EditField is not updating after the selection.
So I've been trying to use just simple text like 'asd' or 'aaa' to test the code, but even these do not show in the text area!
I've been frustrated with this for several hours to find the solution.
Please HELP~
% Callbacks that handle component events
methods (Access = private)
% Callback function: BrowseButton, SelectJDataTextArea
function BrowseButtonPushed(app, event)
clc
clear
[app.dirs, app.dt] = uigetfile('*.csv*','Select data file # 1','E:\directory');
if length(app.dirs) == 0
app.SelectDataTextArea.Value = 'asd';
drawnow;
else
app.SelectDataTextArea.Value = 'aaa';
drawnow;
end
end
0 Comments
Answers (1)
Cris LaPierre
on 16 Jul 2021
Edited: Cris LaPierre
on 16 Jul 2021
What error messages are you getting when you run your code? Please share all the red text.
Remove the clc and clear from inside your callback. That wipes out your function inputs. The drawnows also aren't necessary. You can remove them, too.
Look in the Component Browser to confirm that your text area is named app.SelectDataTextArea. If not, update your code to use the correct name. And just to be clear, the first output of uigetfile is the filename. The second is the path.
% Callback function: BrowseButton, SelectJDataTextArea
function BrowseButtonPushed(app, event)
[app.dirs, app.dt] = uigetfile('*.csv*','Select data file # 1','E:\directory');
if length(app.dirs) == 0
app.SelectDataTextArea.Value = 'asd';
else
app.SelectDataTextArea.Value = 'aaa';
end
end
5 Comments
Cris LaPierre
on 20 Jul 2021
The code I shared in my first post works in an app I created provided the following
- You use a text area
- The text area is named SelectDataTextArea
- The button is named BrowseButton
- To display the selected filename, replace 'aaa' with app.dirs (no quotes, no converting the char or string)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!