Borrar filtros
Borrar filtros

naming saved files in a for loop

2 visualizaciones (últimos 30 días)
Lee Borden
Lee Borden el 12 de Mzo. de 2021
Comentada: Lee Borden el 12 de Mzo. de 2021
I'm attempting to use a for loop to create many different mat files. currently my code is:
for i = 1:length(masq_CU_ID)
savename_masq = strcat(masq_CU_ID(i), '_masq01')
masqpatient = masq01(strcmp(masq01.src_subject_id, masq_CU_ID(i)), :);
save('savename_masq', 'masqpatient');
end
where each iteration of the loop should create a seperate .mat file with a unique title based on what the value of savename_masq is during that iteration of the loop. Currently each loop saves the file as savename_masq.mat, which overwrites whatever was saved in the previous loop.
How do I get the save function to read the value of savename_masq, rather than the variable name?

Respuestas (1)

Stephen23
Stephen23 el 12 de Mzo. de 2021
What you wrote:
save('savename_masq', 'masqpatient');
What you should write:
save(savename_masq, 'masqpatient')
  1 comentario
Lee Borden
Lee Borden el 12 de Mzo. de 2021
I tried that, it gives an error:
Error using save
Must be a text scalar.
Error in Urep2 (line 49)
save(savename_masq, 'masqpatient');
in case it matters, the values in masq_CU_ID (i) appear as letter-letter-number-number-number-number
example: AA0001

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by