Sorry about that, added D7(k) to the mix. It still only prints the first listing, not others. Any other suggestions?
Why does my output formatting not print multiple times?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Kenneth Lamury
il 15 Lug 2016
Commentato: Kenneth Lamury
il 16 Lug 2016
This is the best I can get from this MATLAB 2016 Student source code:
fmt_num10='%10.4f%10.4f%10.4f%10.4f%10.4f%10.4f%10.4f%10.4f%10.4f%10.4f\n';
fmt_str80='%s\n'
for ken=1,KENG;
fprintf(fidout,'TITJ\n')
fprintf(fidout,fmt_str80,TITJ(k,:))
fprintf(fidout,'D6,D7,D8,D10,D11,D12,D13,D14,D15,D16\n')
fprintf(fidout,fmt_num10,[D6(k),D8(k),D10(k),D11(k),D12(k),D13(k), ...
D14(k),D15(k),D16(k)])
end
I'm expecting the following KENG times, but it only prints the last request:
TITJ
*---MAIN GEAR DWT---*
D6,D7,D8,D10,D11,D12,D13,D14,D15,D16
-97.7830 0.0000 221.2340 10.4380 0.9146 0.0000 0.0000 0.0000 0.4043
Risposta accettata
Star Strider
il 15 Lug 2016
One possibility is that your for loop increments ‘ken’ but the only vector reference I can see references ‘k’. I suspect you define ‘k’ somewhere else (perhaps in another loop) in your code earlier, and its value remains the maximum value it reaches in that loop, so the subscript reference would be to that unchanging value.
2 Commenti
Star Strider
il 16 Lug 2016
It should go through the entire loop and print everything at each iteration.
I don’t have your data, but when I do a similar loop:
mtx = randi(9, 5, 6);
fmt = ['\t' repmat('%3.0f', 1, size(mtx,2)) '\n'];
for k1 = 1:size(mtx,1)
fprintf(1, 'Row %.0f:\n',k1)
fprintf(1, fmt, mtx(k1,:))
end
it prints out correctly.
I just noticed that you left out ‘D(7)’ here:
fprintf(fidout,fmt_num10,[D6(k),D8(k),D10(k), ...
Not critical, but you may want to include it.
You can also use the repmat function here:
fmt_num10 = [repmat('%10.4f', 1, 10) '\n'];
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!