rename workspace variables

19 visualizaciones (últimos 30 días)
Joris
Joris el 5 de Ag. de 2011
Comentada: Albert Lu el 24 de Abr. de 2017
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?

Respuesta aceptada

Daniel Shub
Daniel Shub el 5 de Ag. de 2011
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 comentario
Albert Lu
Albert Lu el 24 de Abr. de 2017
Just to point out a small typo here. The last line should be save('newmymat.mat', '-struct', 'x');

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by