Borrar filtros
Borrar filtros

Opening files with different names

3 visualizaciones (últimos 30 días)
Bence Laczó
Bence Laczó el 27 de Jun. de 2023
Respondida: Ram Sreekar el 28 de Jun. de 2023
I am using Matlab to read mat files generated during data collection.
The files have the following format: they start with either anterior, central, posterior, lateral or medial and end with a number (-10,-09,-08,-07,-06,-05,-04,-03,-02,-01,+00,+01,+02,+03,+04,+05).
Example: anterior-10.mat, central+02.mat
After analysis of the data I have mad for example "times_anterior-10.mat" file. These files however doesn't exist for every raw file.
I have two different scripts which I would like to run to further analise the data. I would like to run the 1st script if "times_*.mat" file doesn't exist and I would like to run the 2nd script if "times_*.mat" file exist.
  1 comentario
Stephen23
Stephen23 el 27 de Jun. de 2023
Editada: Stephen23 el 27 de Jun. de 2023
Make a list of all filenames, then use ISFILE or EXIST on them.
What have you tried so far?

Iniciar sesión para comentar.

Respuesta aceptada

Ram Sreekar
Ram Sreekar el 28 de Jun. de 2023
You can run different scripts based on the existence of the "times_*.mat" file by using the ‘exist’ function in MATLAB. You can refer to the example code given below.
% Check if the "times_*.mat" file exists
if exist('times_*.mat', 'file') == 2
% Run the 2nd script if the file exists
run('second_script.m');
else
% Run the 1st script if the file doesn't exist
run('first_script.m');
end
In this code, the ‘exist’ function is used to check if the file "times_*.mat" exists in the current directory. The function returns 2 if the file exists, and 0 otherwise. Based on this result, the appropriate script is executed using the run function.
Please make sure to replace "times_*.mat" with the actual file name required and the script names to the required scripts that you wish to run.
Hope this helps you resolve your query.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by