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

32 visualizaciones (últimos 30 días)
Baejung Kim
Baejung Kim el 16 de Jul. de 2021
Comentada: Cris LaPierre el 20 de Jul. de 2021
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

Respuestas (1)

Cris LaPierre
Cris LaPierre el 16 de Jul. de 2021
Editada: Cris LaPierre el 16 de Jul. de 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 comentarios
Baejung Kim
Baejung Kim el 19 de Jul. de 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 el 20 de Jul. de 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)

Iniciar sesión para comentar.

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by