Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

fprintf 13 data points in 5 rows without zeros

$
0
0
I first change my data set from a matrix to vector using the reshape

A = reshape(OriginalA, numel(A),1)
B = reshape(OriginalB, numel(A),1)

then found the intersection

C=sextor(A,B); (13 by 1 vector)

turnC into a 5x4 matrix
ncol=4
nrow=ceil(numel(C)/ncol);
for i=1:nrows
     for i=1:ncol
          if j == nrows
              extran=nrows-round(numel(C)/ncol)
              for k=1:extran
                    D(nrows,k)=C((i-1)*ncol+k);
          else
               D(i,j)=C(i-1)*ncol+j);
          end
      end
end

Now I want to print it to a file where there are 4 or 8 columns because that was what a separate program wants.
 
d1, d2, d3, d4,
d5, d6, d7, d8,
d9, d10, d11, d12
d13

Tried
for i=1:nrow
      fprintf(fid,'%10i, %10i, %10i, %10,\n',D(i,1),D(i,2),D(i,3),D(i,4))
end
it gives me the zeros though and I don't want them.

Viewing all articles
Browse latest Browse all 19628

Trending Articles