[App designer] Update text area or edit field with uigetfile (filename)

14 views (last 30 days)
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

Answers (1)

Cris LaPierre
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
Baejung Kim
Baejung Kim on 19 Jul 2021
Maybe the question was too vague,
Purpose: file name to appear in the textarea / edit field area upon file is selected by clicking [Browse] button
Problem: The code of adding value to the app.SelectJDataTextArea.Value seems to be not doing the trick.
function BrowseButtonPushed(app, event)
[app.dirs, app.dt] = uigetfile('*.csv*','Select data file # 1','E:\directory');
app.SelectJDataTextArea.Value = char(app.dirs);
So basically nothing happens in the app window without any errors.
Cris LaPierre
Cris LaPierre on 20 Jul 2021
The code I shared in my first post works in an app I created provided the following
  1. You use a text area
  2. The text area is named SelectDataTextArea
  3. The button is named BrowseButton
  4. To display the selected filename, replace 'aaa' with app.dirs (no quotes, no converting the char or string)

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!