Convert a vector to matrix

 

Thread Subject:
Convert a vector to matrix

Subject: Convert a vector to matrix

From: [email protected] (Adel)

Date: 4 May, 2001 11:27:39

Message: 1 of 4

Hi,

Does anyone knows how to convert a vector into a matrix without the
use of the For command.

Thanks.

Subject: Convert a vector to matrix

From: wsun

Date: 4 May, 2001 12:00:40

Message: 2 of 4

Adel,
How about
» reshape(1:10,2,5)
ans =
1 3 5 7 9
2 4 6 8 10

Thanks.
--wsun

adel wrote:

> Hi,

> Does anyone knows how to convert a vector into a matrix without the
> use of the For command.

> Thanks.

Subject: Convert a vector to matrix

From: A.L. Souza

Date: 4 May, 2001 13:05:58

Message: 3 of 4

Hi!

I don't understand you: a vector _is_ a matrix. 

Perhaps you would like to change the dimensions of your vector. If so,
try the reshape command.

Best regards,
Arlan

On 4 May 2001, adel wrote:

> Hi,

> Does anyone knows how to convert a vector into a matrix without the
> use of the For command.

> Thanks.
>

Subject: Convert a vector to matrix

From: Peter J. Acklam

Date: 4 May, 2001 20:02:54

Message: 4 of 4

[email protected] (adel) writes:

> Does anyone knows how to convert a vector into a matrix without
> the use of the For command.

Use RESHAPE -- perhaps in conjunction with the .' operator:

   x = [1 2 3 4 5 6]

   % to fill elements (columns first)
   y = reshape(x, [2 3])

   y =

        1 3 5
        2 4 6

   % to fill elements (rows first), use
   y = reshape(x, [3 2]).'

   y =

        1 2 3
        4 5 6

Peter

-- 
for i=['jamh';'unaa';'sotc';'ttlk';' hae';' ebr';' r '];
i=i'; i=deblank(i); fprintf('%s ',i); end; fprintf('\n');

你可能感兴趣的:(Convert a vector to matrix)