How to assign results to varying filename?

Hi all,
I am trying this:
for i = 1:length(originalData)
['data_hz' '_' num2str(i)] = selectedData(x1:x2);
end
I want to split my original data into different file names, but the code does not allow me to use this structure on the left side of the "=". Any hint please?
Thank you very much :)

 Respuesta aceptada

Image Analyst
Image Analyst el 10 de Mzo. de 2014
Maybe you want some thing like this:
someFolder = 'D:\whatever';
for k = 1 : length(originalData)
baseFileName = sprintf('data_hz_%d.dat', k);
fullFileName = fullfile(someFolder, baseFileName);
save(fullFileName, 'selectedData');
end

1 comentario

M G
M G el 11 de Mzo. de 2014
Thanks.... That's a good way to do but I do not want to save in each loop! It will create tens of files!

Iniciar sesión para comentar.

Más respuestas (1)

Neuroscientist
Neuroscientist el 24 de Abr. de 2014

0 votos

Dear Mehdi,
Perhaps you want to split your data into different variables and not files and to save all of them in a single file. One good way will be to use struct fields, another will be to use cell array.
For struct fields something like this can do the job
for i = 1:length(originalData)
currVar = strcat('data_hz_', num2str(i)); %a meaningful variable name for you
splitData.(currVar) = selectedData(x1:x2); %you can use index also like splitData.(currVar)(i,k)
end
you can re-structure however you want your variables also.

Categorías

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

Etiquetas

Preguntada:

M G
el 10 de Mzo. de 2014

Respondida:

el 24 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by