How to assign results to varying filename?
1 次查看(过去 30 天)
显示 更早的评论
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 :)
0 个评论
采纳的回答
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 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!