How to assign results to varying filename?

조회 수: 2 (최근 30일)
M G
M G 2014년 3월 10일
답변: Neuroscientist 2014년 4월 24일
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 :)

채택된 답변

Image Analyst
Image Analyst 2014년 3월 10일
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
M G
M G 2014년 3월 11일
Thanks.... That's a good way to do but I do not want to save in each loop! It will create tens of files!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Neuroscientist
Neuroscientist 2014년 4월 24일
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.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by