I have two .mat's that each have a list of vectors with the same name. I want to rename the variables of the first .mat to originalname_Ref, and then save all vectors in one .mat. But how do I change the names of the workspace vectors?

 채택된 답변

Daniel Shub
Daniel Shub 2011년 8월 5일

2 개 추천

When you load the .mat file, load it to a variable:
x = load('mymat.mat');
names = fieldnames(x)
for iname = 1:length(names)
x.(['new_', names{iname}]) = x.(names{iname});
x = rmfield(x, names{iname});
end
save('newmymat.mat', '-struct', 's');

댓글 수: 1

Albert Lu
Albert Lu 2017년 4월 24일
Just to point out a small typo here. The last line should be save('newmymat.mat', '-struct', 'x');

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

질문:

2011년 8월 5일

댓글:

2017년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by