Filter löschen
Filter löschen

How to use dlmwrite in a for loop?

2 Ansichten (letzte 30 Tage)
Jose Peñaloza
Jose Peñaloza am 18 Sep. 2015
Kommentiert: Jose Peñaloza am 21 Sep. 2015
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

Akzeptierte Antwort

Joseph Cheng
Joseph Cheng am 18 Sep. 2015
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

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by