Hello everybody,
I have a set of arrays inside the workspace whose names are like the followings: Data1_Asc, Data1_BML, Data2_Asc, Data2_BML... Datan_Asc,Datam_BML.
I want to divide these variables into n different .mat files where each variable inside everyone of these files would be named as:
Data1_Asc, Data1_BML.
Any suggestion?
Thanks

1 comentario

Stephen23
Stephen23 el 19 de Abr. de 2022
Editada: Stephen23 el 19 de Abr. de 2022
"Indexing inside variables name"
Forcing pseudo-indices into variable names is much less efficient than using actual indices.
Accessing numbered variable names forces you into writing slow, complex, inefficient, fragile, obfuscated code.
You did not tell us the most important information: how did you get all of those variables into the workspace?

Iniciar sesión para comentar.

 Respuesta aceptada

Stephen23
Stephen23 el 19 de Abr. de 2022
Editada: Stephen23 el 19 de Abr. de 2022
for k = 1:N
v1 = sprintf('Data%u_Asc',k);
v2 = sprintf('Data%u_BML',k);
fn = sprintf('File%u.mat',k);
save(fn,v1,v2)
end
Better data design would use exactly the same variable names in every file.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Preguntada:

el 19 de Abr. de 2022

Editada:

el 19 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by