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:
repeat array

Subject: repeat array

From: smith Og

Date: 13 Sep, 2010 15:07:20

Message: 1 of 6

If I have an array:

A = [1 2;3 4], is there any function, even in image processing toolbox, that can give me:

B = [1 1 2 2; 1 1 2 2; 3 3 4 4; 3 3 4 4].

Thanks. I know I can use :

C = arrayfun(@ (x) repmat(x,[2,2]), A, 'UniformOutput',false);
D = cell2mat(C).

but I was thinking of a better option

Subject: repeat array

From: Matt Fig

Date: 13 Sep, 2010 15:14:04

Message: 2 of 6

There are methods based on using KRON, but I wrote this to do it more efficiently:

http://www.mathworks.com/matlabcentral/fileexchange/24536-expand

Subject: repeat array

From: Sean

Date: 13 Sep, 2010 15:14:04

Message: 3 of 6

"smith Og" <adeog@ymail.com> wrote in message <i6len8$569$1@fred.mathworks.com>...
> If I have an array:
>
> A = [1 2;3 4], is there any function, even in image processing toolbox, that can give me:
>
> B = [1 1 2 2; 1 1 2 2; 3 3 4 4; 3 3 4 4].
>


It'll be slow for anything big but:
B = kron(A,ones(2))

I think 'expand' on the FEX does this too; you might want to check that out.

Subject: repeat array

From: Matt J

Date: 13 Sep, 2010 16:08:05

Message: 4 of 6


And here's a tool for avoiding such expansions altogether

http://www.mathworks.com/matlabcentral/fileexchange/25969-efficient-object-oriented-kronecker-product-manipulation

Subject: repeat array

From: Bruno Luong

Date: 13 Sep, 2010 17:50:26

Message: 5 of 6

I expect this code is faster than KRON

 [m n]=size(A)
 nrep=3
 reshape(repmat(reshape(A,[1 m 1 n]),[nrep 1 nrep 1]),[m n]*nrep)

Bruno

Subject: repeat array

From: gianni schena

Date: 14 Sep, 2010 09:57:05

Message: 6 of 6



"smith Og" <adeog@ymail.com> wrote in message <i6len8$569$1@fred.mathworks.com>...
> If I have an array:
>
> A = [1 2;3 4], is there any function, even in image processing toolbox, that can give me:
>
> B = [1 1 2 2; 1 1 2 2; 3 3 4 4; 3 3 4 4].

what about ...

>> imresize(A,2,'nearest')

ans =

     1 1 2 2
     1 1 2 2
     3 3 4 4
     3 3 4 4

Tags for 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