f



[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 3;....;n n n n n]

Hi,
Anybody knows how to create this matrix but without using any loops?
a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ]

Thank you.
Hana.
0
m007154 (19)
12/2/2005 6:25:48 PM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

9 Replies
1908 Views

Similar Articles

[PageSpeed] 22

Hana wrote:
> Hi,
> Anybody knows how to create this matrix but without using any loops?
> a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ]

HELP REPMAT

          - Randy

0
poespam-trap (1550)
12/2/2005 6:19:38 PM
Hana wrote:
>
>
> Hi,
> Anybody knows how to create this matrix but without using any
> loops?
> a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ]
>
> Thank you.
> Hana.

Hope this isn't homework.

>> repmat([1:n]',[1 5])
0
thecyclist (382)
12/2/2005 6:29:06 PM
repmat([1:n]', 1, n);

Booya

Hana wrote:
>
>
> Hi,
> Anybody knows how to create this matrix but without using any
> loops?
> a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ]
>
> Thank you.
> Hana.
0
sdoherty (24)
12/2/2005 6:30:01 PM
the cyclist wrote:
>
>
> Hana wrote:
>>
>>
>> Hi,
>> Anybody knows how to create this matrix but without using any
>> loops?
>> a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ]
>>
>> Thank you.
>> Hana.
>
> Hope this isn't homework.
>
>>> repmat([1:n]',[1 5])
Thank you for your help.
dont worry it is not a homework.

Hana
0
m007154 (19)
12/2/2005 6:32:51 PM
Something like this...
al=linspace(1,n,n);
a=repmat(al',1,n);

"Hana" <m007154@squ.edu.om> skrev i meddelandet 
news:ef1d5ca.-1@webx.raydaftYaTP...
> Hi,
> Anybody knows how to create this matrix but without using any loops?
> a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ]
>
> Thank you.
> Hana. 


0
huanbj (458)
12/6/2005 11:02:39 PM
Hana:
<SNIP simple mat creation...

> a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ]

one of the many (other) solutions

% the parameters
     nr=5;
     n=10;
% the engine
     a=1:n;
% the result
     a=a(ones(nr,1),:).'

us
0
us1 (8051)
12/6/2005 11:55:27 PM
us:
<SNIP simple mat creation...

-and- just in case you wondered about - other - solutions (besides
the obvious <repmat>)...

% the parameters
     nr=5;
     n=8;
% the engine
     a=ones(n,nr);
     a=cumsum(a);
% the result
     a

us
0
us1 (8051)
12/7/2005 12:02:56 AM
us wrote:
>
>
> us:
> <SNIP simple mat creation...
>
> -and- just in case you wondered about - other - solutions (besides
> the obvious <repmat>)...
>
> % the parameters
> nr=5;
> n=8;
> % the engine
> a=ones(n,nr);
> a=cumsum(a);
> % the result
> a
>
> us

% or ...
n = 8 ; nc = 5 ;
m = diag(1:n) * ones(n,nc) ;

Jos
0
Jos
12/7/2005 9:45:07 AM
Jos wrote:
>
>
> us wrote:
>>
>>
>> us:
>> <SNIP simple mat creation...
>>
>> -and- just in case you wondered about - other - solutions
> (besides
>> the obvious <repmat>)...
>>
>> % the parameters
>> nr=5;
>> n=8;
>> % the engine
>> a=ones(n,nr);
>> a=cumsum(a);
>> % the result
>> a
>>
>> us
>
> % or ...
> n = 8 ; nc = 5 ;
> m = diag(1:n) * ones(n,nc) ;
>
> Jos

% or

m = kron(1:nc,ones(n,1))

/PB
0
PB
12/7/2005 8:41:13 PM
Reply: