Opening files with different names
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Ram Sreekar
2023-6-28
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!