How to use dlmwrite in a for loop?

3 次查看(过去 30 天)
Hi everybody, I want to use dlmwrite to save data in .dat format for a cell array in the workspace.
Thats what I want obtain:
dlmwrite('Ejex1.dat', Ejex{1,1}','delimiter','\t','precision',16)
dlmwrite('Ejex2.dat', Ejex{1,2}','delimiter','\t','precision',16)
dlmwrite('Ejey1.dat', Ejey{1,1},'delimiter','\t','precision',16)
dlmwrite('Ejey2.dat', Ejey{1,2}','delimiter','\t','precision',16)
But the problem is when I try to put in a for loop, I tried many ways to obtain that but it doesn't work well:
for i=1:numfiles
NameFile(i)=filename(i)
dlmwrite('NameFile%d.dat',Ejex{1,i},'delimiter','\t','precision',16)
end
Another:
for i=1:numfiles
NameFile(i)=filename(i)
dlmwrite(NameFile.dat, Ejex{1,i},'delimiter','\t','precision',16)
end
Thanks in advance!! I hope you can help me

采纳的回答

Joseph Cheng
Joseph Cheng 2015-9-18
matlab is not going to fill in the %d number for you. you should be using something like sprintf to a variable to generate the filename for dlmwrite.
for i = 1:size(Ejex,1)
Xfilename = sprintf('Ejex%d.dat',i);
disp(Xfilename)%use xfilename for your dlmwrite
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by