0

I have multiple .mat files (more than 100). I am running a code where I have to load the files. The name of the .mat files are saved as (lets consider only 10 files),

loc_1_test.mat, loc_3_test.mat, loc_4_test.mat, loc_5_test.mat, loc_6_test.mat, loc_8_test.mat, loc_10_test.mat, loc_11_test.mat, loc_13_test.mat, loc_16_test.mat

I mean to say that if you have a look on these .mat files then the names are not evenly distributed. That means I believe it will be easy to load if the above names of the .mat files will be like,

loc_1_test.mat, loc_2_test.mat, loc_3_test.mat, loc_4_test.mat, loc_5_test.mat, loc_6_test.mat, loc_7_test.mat, loc_8_test.mat, loc_9_test.mat, loc_10_test.mat

Is there any way to change the name of the .mat files like this? Or the only option is to change them manually? Changing the names of over 100s of .mat files manually are very much time taking.

Can anyone please help? Thanks.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Bruce Denby
  • 71
  • 1
  • 5
  • 3
    Get the names by `dir` or `ls`. Change them by `strsplit`, or `regexp`. Then save it by `movefile`. – Adiel Dec 13 '15 at 13:58
  • Consider studying the following page: http://www.mathworks.com/matlabcentral/answers/1760-how-to-rename-a-bunch-of-files-in-a-folder – brainkz Dec 13 '15 at 14:40
  • 2
    To follow up on @Adiel's comment, see http://stackoverflow.com/questions/11621846/loop-through-files-in-a-folder-in-matlab. You really shouldn't have to rename the files at all to achieve what you want. – beaker Dec 13 '15 at 15:11
  • Thanks @beaker, it's a great trick! – Adiel Dec 16 '15 at 07:15

0 Answers0