Borrar filtros
Borrar filtros

Check for .txt or .mat file

61 visualizaciones (últimos 30 días)
Evans Gyan
Evans Gyan el 5 de Feb. de 2018
Comentada: Jan el 30 de Mayo de 2021
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

Respuestas (1)

Jan
Jan el 5 de Feb. de 2018
[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 comentarios
Alessandro Maria Laspina
Alessandro Maria Laspina el 30 de Mayo de 2021
Editada: Alessandro Maria Laspina el 30 de Mayo de 2021
This did not for me, has it changed in R2021 or releases past 2018?
Jan
Jan el 30 de Mayo de 2021
@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.

Iniciar sesión para comentar.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by