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?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2016년 7월 15일
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
Star Strider
2016년 7월 16일
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'];
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!