Rename and save multiple .mat files.

조회 수: 10 (최근 30일)
caesar
caesar 2019년 10월 13일
댓글: caesar 2019년 10월 15일
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
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.
caesar
caesar 2019년 10월 15일
Ok , sorry if did confuse you . assume I have the following code
all=[];
first_1=[1 1 1 1 1 1];
first_2=[2 2 2 2 2 2];
first_3=[3 3 3 3 3 3];
save('firs_1.mat','first_1');
save('firs_2.mat','first_2');
save('firs_3.mat','first_3');
and I want to :
1- load first_1.mat,firs_2.mat and firs_3.mat
3- rename vectors first_1,first_2 and first_3 to:
first_11,first_12,first_13
3- save them in mat files :
firs_11.mat,firs_12.mat and firs_13.mat
3 - Form ALL that looks like :
all =
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
I hope this time its clearer
thanks

댓글을 달려면 로그인하십시오.

답변 (1개)

per isakson
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?

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by