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:
expand matrix

Subject: expand matrix

From: Tomas Fridrich

Date: 4 Apr, 2013 12:34:07

Message: 1 of 3

Hello,

I want to expand matrix. I got for example matrix A=
1 1
1 1

and I would like to expand it to

0 0 0 0
0 1 1 0
0 1 1 0
0 0 0 0

how to solve it?

Thanks

Tomas

Subject: expand matrix

From: Andrew

Date: 4 May, 2013 04:14:11

Message: 2 of 3

Hi Tomas,

I think I could help you with this, but I need more information about your problem.
Please describe exactly what you mean by 'expand'. I just want to double check, it looks like you want to take your matrix and add a square of zeros all around it. I presume you want to do this multiple times, and with any size matrix?

Is this correct?

Here to help,

Andrew Reibold


"Tomas Fridrich" <fridrichtomas@gmail.com> wrote in message <kjjrvv$lql$1@newscl01ah.mathworks.com>...
> Hello,
>
> I want to expand matrix. I got for example matrix A=
> 1 1
> 1 1
>
> and I would like to expand it to
>
> 0 0 0 0
> 0 1 1 0
> 0 1 1 0
> 0 0 0 0
>
> how to solve it?
>
> Thanks
>
> Tomas

Subject: expand matrix

From: Bruno Luong

Date: 4 May, 2013 07:37:13

Message: 3 of 3

"Tomas Fridrich" <fridrichtomas@gmail.com> wrote in message <kjjrvv$lql$1@newscl01ah.mathworks.com>...
> Hello,
>
> I want to expand matrix. I got for example matrix A=
> 1 1
> 1 1
>
> and I would like to expand it to
>
> 0 0 0 0
> 0 1 1 0
> 0 1 1 0
> 0 0 0 0
>

B = zeros(size(A)+2);
B(2:end-1,2:end-1) = A

% Bruno

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