フィルターのクリア

Error with uigetfile in App Designer when changing directories

2 ビュー (過去 30 日間)
Scotty Mac
Scotty Mac 2023 年 7 月 11 日
コメント済み: Scotty Mac 2023 年 7 月 11 日
I have the following code to read in a csv file:
% Allow the user to select any CSV file
[file, path] = uigetfile('*.csv');
if isequal(file,0)
% User selected cancel
return;
else
comp_fn = readtable(file);
handles.comp_fn = comp_fn;
guidata(hObject, handles);
end
I am receiving an error when I traverse directories using the uigetfile UI to select the file. If the requested file is in the same directory when the UI opens, it loads correctly. If I change to a different directory and select a valid file, I receive a 'Unable to find or open file XXX' error (when I just selected it).
What am I missing? Do I have include the path to that file? If so, how is this done in the above code? I tried searching for this answer, without any luck.
Thanks in advance.

採用された回答

Voss
Voss 2023 年 7 月 11 日
Use the full path, not just the file name:
comp_fn = readtable(fullfile(path,file));
  1 件のコメント
Scotty Mac
Scotty Mac 2023 年 7 月 11 日
That fixed the issue. Many thanks!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by