[App designer] Update text area or edit field with uigetfile (filename)
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Cris LaPierre
am 16 Jul. 2021
Bearbeitet: Cris LaPierre
am 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 Kommentare
Cris LaPierre
am 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)
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!