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

Re: fprintf 13 data points in 5 rows without zeros

$
0
0
On 7/15/2013 9:36 AM, Mark wrote:
> 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
...

...[code elided for brevity]...

The posted code is malformed w/ an incomplete for... nested inside an
if...else... block so can't begin to tell what is the intent.

But, a 13-element vector won't make a 5x4 matrix no matter how you try
to code it--you're short 7 elements.


> Now I want to print it to a file where there are 4 or 8 columns because
> that was what a separate program wants.
...

> it gives me the zeros though and I don't want them.

Again, you have a mismatch in the numbers; those extra locations have to
be something or you have to not print the extraneous values...

To print n elements per line, simply use sotoo...

 >> nperlin=4;sprintf([repmat('%4d ',1,nperlin-1),'%4d\n'],[1:13])
ans =
    1 2 3 4
    5 6 7 8
    9 10 11 12
   13
 >>

--

Viewing all articles
Browse latest Browse all 19628

Trending Articles