Rename and save multiple .mat files.
6 次查看(过去 30 天)
显示 更早的评论
Hi
I am trying to load, rename and save a group of mat files . so far I am using this code :
cd 'E:\Mat'
fileFolder = fullfile('E:\','Mat');
% cd (fileFolder)
dirOutput = dir(fullfile(fileFolder,'*.mat'));
fileNames = {dirOutput.name};
for k=1:length(fileNames)
H=fileNames{k};
movefile(H, sprintf('All_state_action_qs_%03d.mat', k));
end
although it does rename all the files properly, when I load any files (with new name) the name on the work space is the old name.
Therfore, I guess there is a way for doing Load>Rename>save again in a batch fashion.
regards
4 个评论
Stephen23
2019-10-15
@caesar: putting numbers into variable names is a sign that you are doing something wrong. It is unlikely to help you, just make your code complex, slow, obfuscated, and buggy.
"also I would be grateful if you can tell me how can extract the vector from within those mat files and stack them in one N*24 matrix"
I get the feeling that you are not actually asking us what you are really trying to achieve:
Probably it would also help if you uploaded some sample data, by clicking the paperclip button.
回答(1 个)
per isakson
2019-10-14
"the name on the work space is the old name" What do you expect? It's the names of the variables contained in the mat-file. They aren't affected by the name of the mat-file.
How exactly do you load the renamed mat-file?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!