Check for .txt or .mat file

조회 수: 48 (최근 30일)
Evans Gyan
Evans Gyan 2018년 2월 5일
댓글: Jan 2021년 5월 30일
Hello Guys, i want to find out how to determine if an input or selected file from a user is .txt or.mat file. I used this syntax to pick the user input. [filename pathname] = uigetfile({'*.mat'; '*.txt'},'File Selector'); Then i can use it for different functions. Thanks In advance

답변 (1개)

Jan
Jan 2018년 2월 5일
[fPath, fName, fExt] = fileparts(filename);
switch lower(fExt)
case '.mat'
% A MAT file
case '.txt'
% A Text file
otherwise % Under all circumstances SWITCH gets an OTHERWISE!
error('Unexpected file extension: %s', fExt);
end
  댓글 수: 4
Alessandro Maria Laspina
Alessandro Maria Laspina 2021년 5월 30일
편집: Alessandro Maria Laspina 2021년 5월 30일
This did not for me, has it changed in R2021 or releases past 2018?
Jan
Jan 2021년 5월 30일
@Alessandro Maria Laspina: This piece of copde does work in R2021a also. If your code does not work, post it in a new question and explain the details.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by