fprintf break line different arrays
Mostra commenti meno recenti
[Edited] I use 2 arrays here as examples but I actually have several
I have the following arrays:
a=[1 2 3 4 5 6 7 8 9 10 11];
b=[12 13 14 15 16];
And I want to write a text file that gives me:
1 2 3 4 5 6 7 8 9 10
11
12 13 14 15 16
This is my code:
fmti = repmat(' % 12d',1,10);
fmti = [fmti(2:end),'\n'];
fprintf(file,fmti,a);
fprintf(file,fmti,b);
However this gives me a file where 1 through 10 are written on the same line and 11 through 16 are on the same line.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16
I know it's because I set the number of elements to 10 (and that is because the maximum number of elements per line will always be 10) but I would like fprintf to do a break line when it prints different vectors.
I need a code that will always write 10 elements per line maximum but will write different vectors in different lines.
Any help is appreciated, thank you!
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Cell Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!