Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
tabulate.m

Subject: tabulate.m

From: Jade

Date: 27 Feb, 2005 12:51:01

Message: 1 of 6

Hi, all
I would like to ask the function tabulate.m...

TABLE = TABULATE(X) takes a vector of positive integers, X, and
returns a matrix, TABLE.

my question is there any function that can takes a vector of
positive, zero and negative integers ?

Many thanks and Best Regards
Jade

Subject: tabulate.m

From: Michael Robbins

Date: 27 Feb, 2005 13:00:05

Message: 2 of 6

Jade wrote:
>
>
> Hi, all
> I would like to ask the function tabulate.m...
>
> TABLE = TABULATE(X) takes a vector of positive integers, X, and
> returns a matrix, TABLE.
>
> my question is there any function that can takes a vector of
> positive, zero and negative integers ?
>
> Many thanks and Best Regards
> Jade

Use FPRINTF:

fprintf([repmat('%6.3f ',size(M,1),1) '\n'],M.');

I don't have MATLAB here, so I can't test the syntax. You may have
to use size(M,2) instead of size(M,1), or switch the size statement
and the 1 "...,1,size(M,1))"

If you try a few variations, you'll get it to work.

Also, if you want more or fewer digits, adjust the "6.3"

Look at HELP FPRINTF to see how to do that.

Subject: tabulate.m

From: Michael Robbins

Date: 27 Feb, 2005 22:48:00

Message: 3 of 6

This is what I meant:

>> M=rand(5);
>> M
M = 0.2028 0.0153 0.4186 0.8381 0.5028
    0.1987 0.7468 0.8462 0.0196 0.7095
    0.6038 0.4451 0.5252 0.6813 0.4289
    0.2722 0.9318 0.2026 0.3795 0.3046
    0.1988 0.4660 0.6721 0.8318 0.1897

>> fprintf([repmat('%6.3f ',1,size(M,1)) '\n'],M.');
 0.203 0.015 0.419 0.838 0.503
 0.199 0.747 0.846 0.020 0.709
 0.604 0.445 0.525 0.681 0.429
 0.272 0.932 0.203 0.379 0.305
 0.199 0.466 0.672 0.832 0.190

>> fprintf([repmat('%9.8f ',1,size(M,1)) '\n'],M.');
0.20276522 0.01527393 0.41864947 0.83811845 0.50281288
0.19872174 0.74678568 0.84622142 0.01963951 0.70947139
0.60379248 0.44509643 0.52515250 0.68127716 0.42889237
0.27218792 0.93181458 0.20264736 0.37948102 0.30461737
0.19881427 0.46599434 0.67213747 0.83179602 0.18965375

Subject: tabulate.m

From: Jade

Date: 27 Feb, 2005 23:30:54

Message: 4 of 6

Dear Michael ,
Thanks your reply, but I would like to clarify that tabulate.m
perform the following function:

>>A =

     1 1 1 1
     2 2 28 5
     5 3 9 1
>> TABLE = tabulate(A(:))

TABLE =

    1.0000 5.0000 41.6667
    2.0000 2.0000 16.6667
    3.0000 1.0000 8.3333
    4.0000 0 0
    5.0000 2.0000 16.6667
    6.0000 0 0
    7.0000 0 0
    8.0000 0 0
    9.0000 1.0000 8.3333
   10.0000 0 0
   11.0000 0 0
   12.0000 0 0
   13.0000 0 0
   14.0000 0 0
   15.0000 0 0
   16.0000 0 0
   17.0000 0 0
   18.0000 0 0
   19.0000 0 0
   20.0000 0 0
   21.0000 0 0
   22.0000 0 0
   23.0000 0 0
   24.0000 0 0
   25.0000 0 0
   26.0000 0 0
   27.0000 0 0
   28.0000 1.0000 8.3333

Kindly wait for any reply.
Jade

Subject: tabulate.m

From: Jerome

Date: 28 Feb, 2005 02:29:07

Message: 5 of 6

Hi,

try this :

A=[ -1 1 0 1 ; ...
    2 2 3 5 ; ...
    0 3 9 1 ; ...
    -15 1 8 0]

% All values between min & max of A
% x=(min(min(A)):max(max(A)))';

% Only with value of A
x=unique(A);

nbx=zeros(length(x),1);
pctx=zeros(length(x),1);

for n=1:length(x)
    
    nbx(n)=numel(find(A==x(n)));
    pctx(n)=round(1E7*nbx(n)/numel(A))/1E5;
    
end

data=[x nbx pctx];

sprintf('%d %d %2.5f %%\n',data')
sprintf('Percentage Check : %.1f %%',sum(pctx))

Jérôme

Subject: tabulate.m

From: Jade

Date: 3 Mar, 2005 05:06:27

Message: 6 of 6

Dear Jérôme,
Thank you very much, it really works and wonderful.
Thanks and Best Regards
Jade

Tags for this Thread

No tags are associated with this thread.

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.

Contact us