How to detect which type of data user selected 'text' or 'excel' file via "uigetfile" and then perform further code?
2 ビュー (過去 30 日間)
古いコメントを表示
i have written a code that allows user to input data and give both options of "text" and "Excel"..that is
[filename, pathname] = uigetfile({'*.xlsx','Excel Files(*.xlsx)'; '*.txt','Txt Files(*.txt)'}, 'Pick a file');
if '*.xlsx' % if excel file select
disp('User Selected Excel File.');
else
disp('User Selected Text File.');
end
% i tried isfile function but is detects data type.. kindly Guide. Thanks
0 件のコメント
採用された回答
Cris LaPierre
2021 年 2 月 19 日
Use this syntax of uigetfile
Here, indx corresponds to what filter was selected (see here). If that doesn't work, you can implement your own check using fileparts.
Here, ext will be the file extension of filename.
3 件のコメント
Cris LaPierre
2021 年 2 月 20 日
編集済み: Cris LaPierre
2021 年 2 月 21 日
I understand what you are trying to do, but you have not coded it correctly. For example
if '*.xlsx' % if excel file select
does nothing right now because you have not correctly set up the conditional statement.
I suggest going through Ch 13 of MATLAB Onramp, which will introduce you to if statements. Perhaps that will help you see how to use what I shared to obtain what you want.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!