Opening files with different names
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bence Laczó
le 27 Juin 2023
Réponse apportée : Ram Sreekar
le 28 Juin 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 commentaire
Réponse acceptée
Ram Sreekar
le 28 Juin 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!