Create and save a file in a for cycle
Mostrar comentarios más antiguos
Hi all,
My problem is a bit complex so I will try to explain as best I can.
I have data in 3 columns
Hs Tp Dir 2 3 200 3 2 100 2 3 320
I would like to create a new file with each row, so my first file it would be: a1.txt Hs=2 Tp=3 Dir=200
My second file a2.txt Hs=3 Tp=2 Dir=100
...
The problem is how I can do that...because if I want to use the function fprintf I would need to open the files before and the dmlwrite can not insert text in the matrix....
This is my code:
B=zeros; [m,n] = size(A);
for a = 1:1 fileout=strcat(CurrentDirectory,'a',a,'.txt'); Resultado=fopen('%What??');
Hm0= A(a,1);
fp= A(a,2);
mainang= A(a,3);
fprintf(Resultado,'Hm0= %1.3f \n fp= %1.3f \n mainang=%1.3f',Hm0,fp,mainang);
%MY SECOND OPTION
V={'Hmo=';'fp=';'mainang='};
Z={Hm0;fp;mainang};
B={V Z};
dmlwrite(fileout, B);
end
Respuesta aceptada
Más respuestas (1)
Javier Abanades
el 25 de Feb. de 2013
0 votos
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!