matrix - Using fprintf to print on several lines in Matlab -
question: write procedure called print7 print integer numbers within range 0:100 divisible 7. ten numbers printed on 1 output line. hence write program invokes procedure.
this did
file = fopen('print7.dat','r'); x = 1:100 x=[1:100] if mod(x,7) == 0; print7 = [x] end end fprintf('print7 %d\n', print7)
now it's output becomes number 98 - understand largest number under 100 divisible 7. want 10xn matrix-like result.
what do?
what doing stores result in variable , overwrites variable in each iteration. print directly instead this:
c=0; x=[1:100] if mod(x,7) == 0 fprintf('%3d',x) c=c+1; if mod(c,10) ==0 fprintf('\n') end end end
Comments
Post a Comment