How do I rename the .mat files in a for loop?
Show older comments
I have 1000 .mat files. for example, angle1.mat, angle2.mat, angle3.mat.....angle1000.mat. I want to rename these respective files as angle501.mat, angle502.mat, angle503.mat.....angle1500.mat. Something like I wanted to add 500 to the number.
S = dir('*.mat');
fileNames = {S.name};
for k=1:length(fileNames)
H=fileNames{k};
movefile(H, sprintf('angle%d.mat', k));
end
I think we need to change something inside the sprintf, but don't know how to do it. May I know how to solve the issue?
Thanks.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!