Thread Subject: print matrix in a limited dimensison

Subject: print matrix in a limited dimensison

From: John Wong

Date: 23 Sep, 2009 12:24:03

Message: 1 of 2

Hi guys.

This is the code I had.
   for j=1:realmax
        if mod(j,10)==0
            fprintf('\n');
            fprintf('%g, ',j);
        else
         fprintf('%g, ',j);
        end
    end


as you see, the purpose of this is to print a similar matrix like the following:

A=
1 2 3 4 5 6 7 8 9 10 (oops, 10 already, now auto skip to next line)
11 ------------------>20 (oops, another 10, now auto skip to the next line)
|
|
|
keep going until reaches the limit

I know there is a easy way to write this. I just don't remember how. I have read it somewhere. May anyone helps me out on this?
I know there is a really short cut using one of the matrices function (size, something like that) to print out the that.

Let say 1-100

Subject: print matrix in a limited dimensison

From: Sebastiaan

Date: 23 Sep, 2009 12:45:04

Message: 2 of 2

Not sure what you really want. I assume you have a matrix A, which is 1xN, which you are trying to print in columns of 10?

A = 1:33;

% As a one-liner:
fprintf(sprintf('%s\n',repmat('%7.4f ', 1, 10)), A); fprintf('\n');

If you want to let Matlab to the formatting:
B = zeros(10, ceil(numel(A)/10));
B(1:numel(A)) = A(:);
disp(B')

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
print matrix Sprinceana 23 Sep, 2009 13:40:21
matrix Sprinceana 23 Sep, 2009 13:40:21
rssFeed for this Thread

Contact us at files@mathworks.com