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:
Padding in Matrice.

Subject: Padding in Matrice.

From: Rushi

Date: 8 Oct, 2010 19:13:03

Message: 1 of 4

I have a matrix as follows:

     1 1 1 1 1 1 1 1 1 1 1 1
     1 1 1 1 1 1 1 1 1 1 1 1
     1 1 1 1 1 1 1 1 1 1 1 1
     1 1 1 1 1 1 1 1 1 1 1 1
     1 1 1 1 1 1 1 1 1 1 1 1

I want to pad another row and a column as follows

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

I have a non square matrix and size of the matrix is not fixed.

Thanks.

Subject: Padding in Matrice.

From: Matt J

Date: 8 Oct, 2010 19:25:04

Message: 2 of 4

"Rushi " <rushidesai2012@u.northwestern.edu> wrote in message <i8nqfv$359$1@fred.mathworks.com>...
>
> I want to pad another row and a column as follows
>
> 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 1 1 1 1 1 1 1 1 1 1 1 1
> 0 1 1 1 1 1 1 1 1 1 1 1 1
> 0 1 1 1 1 1 1 1 1 1 1 1 1
> 0 1 1 1 1 1 1 1 1 1 1 1 1
> 0 1 1 1 1 1 1 1 1 1 1 1 1
>
======

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

Subject: Padding in Matrice.

From: Sean

Date: 8 Oct, 2010 19:27:04

Message: 3 of 4

"Rushi " <rushidesai2012@u.northwestern.edu> wrote in message <i8nqfv$359$1@fred.mathworks.com>...
> I have a matrix as follows:
>
> 1 1 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1 1 1
>
> I want to pad another row and a column as follows
>
> 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 1 1 1 1 1 1 1 1 1 1 1 1
> 0 1 1 1 1 1 1 1 1 1 1 1 1
> 0 1 1 1 1 1 1 1 1 1 1 1 1
> 0 1 1 1 1 1 1 1 1 1 1 1 1
> 0 1 1 1 1 1 1 1 1 1 1 1 1
>
> I have a non square matrix and size of the matrix is not fixed.
>
> Thanks.

If you have the Image Processing Toolbox
M = your ones matrix
M2 = padarray(M,[1 1],0,'pre');

If not:
M2 = zeros(size(M)+1)
M2(2:end,2:end) = M;

Subject: Padding in Matrice.

From: Janis Doebler

Date: 11 Oct, 2010 11:45:05

Message: 4 of 4

A = [zeros(1,size(A,2)+1); zeros(size(A,1),1) A]

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