[App designer] Update text area or edit field with uigetfile (filename)
15 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Cris LaPierre
2021-7-16
编辑:Cris LaPierre
2021-7-16
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 个评论
Cris LaPierre
2021-7-20
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!