rename workspace variables
5 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
Daniel Shub
2011 年 8 月 5 日
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
2017 年 4 月 24 日
Just to point out a small typo here. The last line should be save('newmymat.mat', '-struct', 'x');
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Workspace Variables and MAT Files についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!