MATLAB Answers

Load mat files matching specific string inclusive of different strings

20 views (last 30 days)
Mohammed  Yousuf
Mohammed Yousuf on 26 Sep 2021 at 8:37
Commented: KSSV on 26 Sep 2021 at 9:55
I have a folder which consist of n number of .mat files, the names of the files are like mentioned below (latest residuals in log10 of year 2002 to 2020, altitude, latitude , longitude)
latest_res_log102002_alt
latest_res_log102002_lat
latest_res_log102002_long
latest_res_log102003_alt
latest_res_log102003_lat
latest_res_log102003_long
.
.
.
.
latest_res_log102020_long
I would like to load the files three at a time when required by searching the year only. viz.
latest_res_log102015_alt, latest_res_log102015_lat and latest_res_log102015_long.
How to do that. PLease help me.
  1 Comment
Mohammed  Yousuf
Mohammed Yousuf on 26 Sep 2021 at 8:39
latest_res_log102002_alt.mat
latest_res_log102002_lat.mat
latest_res_log102002_long.mat

Sign in to comment.

Accepted Answer

KSSV
KSSV on 26 Sep 2021 at 9:10
matFiles = dir('*.mat') ;
matFiles_name = {matFiles.name} ;
idx = find(~cellfun(@isempty,strfind(matFiles_name,'2015'))) ;
matFiles_name(idx)
  4 Comments
KSSV
KSSV on 26 Sep 2021 at 9:55
Then instead of 2015 give log102005. Change the string to your requirement.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!