Follow by Email

Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Adding elements to a 2d array

A=[100 230 11; 22 10 15; 2 3 90;]

A =

   100   230    11
    22    10    15
     2     3    90

To add a row at the beginning:

A=[[10 20 30]; A]

A =

    10    20    30
   100   230    11
    22    10    15
     2     3    90

To add a row at the end:

A=[A; [10 20 30];]

A =

   100   230    11
    22    10    15
     2     3    90
    10    20    30


To add a column at the beginning:

A=[[10; 20 ;30] A]

A =

    10   100   230    11
    20    22    10    15
    30     2     3    90


To add a column at the end:

A=[A [10; 20 ;30]]

A =

   100   230    11    10
    22    10      15    20
     2     3        90    30


To add a row in the middle:


A=[10 12 14 16; 3 6 9 12; 4 8 12 16; 5 10 15 20;]

A =

    10    12    14    16
     3     6     9    12
     4     8    12    16
     5    10    15    20


A=[A(1:2,:); [8 16 24 32]; A(3:4,:);]

A =

    10    12    14    16
     3     6     9    12
     8    16    24    32
     4     8    12    16
     5    10    15    20

To add a column in the middle:


A=[A(:,1:2) [100; 200; 300; 400;] A(:,3:4)]

A =

    10    12   100    14    16
     3     6     200     9    12
     4     8     300    12    16
     5    10    400    15    20



like button Like "IMAGE PROCESSING" page

0 comments:

Enjoyed Reading? Share Your Views

Previous Post Next Post Home

Link

Related Posts Plugin for WordPress, Blogger...
Google ping Hypersmash.com