How to use dlmwrite in a for loop?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jose Peñaloza
le 18 Sep 2015
Commenté : Jose Peñaloza
le 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
0 commentaires
Réponse acceptée
Joseph Cheng
le 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!