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:
How to make a new matrix[n+1,n+1] based in a previous one [n,n]. The new one needs to have 0's in a determined row and column!

Subject: How to make a new matrix[n+1,n+1] based in a previous one [n,n]. The new one needs to have 0's in a determined row and column!

From: what ever

Date: 17 Mar, 2010 05:26:03

Message: 1 of 3

HELLO!! :)
need help people!!

imagine: M=[1,2,3 ;
                      4,5,6 ;
                      7,8,9]

now i say: x=2 (needs to be to any x; in this case x between 1 and 3!)

the new matrix should be:

NEW_M=[ 1,0,2,3 ;
               0,0,0,0 ;
               4,0,5,6 ;
               7,0,8,9 ]
              
I tried a lot, but i have problems putting the values: 2,3,4 and 7(for this especific case). It appears zero!


My code is:
        
for hh=1:aux_invB
            for j=1:aux_invB
                hh2=hh;
                j2=j;

                   if j<REFBUS && hh<REFBUS

                       t_aux_invB2(hh2,j2)=MB2(hh,j);

                   end

                   if hh>REFBUS-1 && j>REFBUS-1
                       
                        t_aux_invB2(hh2+1,j2+1)=MB2(hh,j);
                         
                   end
            end
end

I deleted the part of the code when 'j' and 'hh' are ==REFBUS because it was bad!! :(
This code needs to be for a generalized matrix, the size of the matrix should not matter!!

Can someone help me pleaseee??

Subject: How to make a new matrix[n+1,n+1] based in a previous one [n,n]. The new one needs to have 0's in a determined row and column!

From: James Tursa

Date: 17 Mar, 2010 07:20:21

Message: 2 of 3

"what ever" <vasco_taveira@hotmail.com> wrote in message <hnpp5b$e2l$1@fred.mathworks.com>...
> HELLO!! :)
> need help people!!
>
> imagine: M=[1,2,3 ;
> 4,5,6 ;
> 7,8,9]
>
> now i say: x=2 (needs to be to any x; in this case x between 1 and 3!)
>
> the new matrix should be:
>
> NEW_M=[ 1,0,2,3 ;
> 0,0,0,0 ;
> 4,0,5,6 ;
> 7,0,8,9 ]
>
> I tried a lot, but i have problems putting the values: 2,3,4 and 7(for this especific case). It appears zero!
>
>
> My code is:
>
> for hh=1:aux_invB
> for j=1:aux_invB
> hh2=hh;
> j2=j;
>
> if j<REFBUS && hh<REFBUS
>
> t_aux_invB2(hh2,j2)=MB2(hh,j);
>
> end
>
> if hh>REFBUS-1 && j>REFBUS-1
>
> t_aux_invB2(hh2+1,j2+1)=MB2(hh,j);
>
> end
> end
> end
>
> I deleted the part of the code when 'j' and 'hh' are ==REFBUS because it was bad!! :(
> This code needs to be for a generalized matrix, the size of the matrix should not matter!!
>
> Can someone help me pleaseee??

Assuming a square M matrix:

x = 2;
[m n] = size(M);
y = [1:(x-1) (x+1):(n+1)];
NEW_M = zeros(m+1,n+1);
NEW_M(y,y) = M;

James Tursa

Subject: How to make a new matrix[n+1,n+1] based in a previous one [n,n]. The new one needs to have 0's in a determined row and column!

From: what ever

Date: 17 Mar, 2010 16:56:21

Message: 3 of 3

Thanks a lot James!!!!!
really!!!
:)

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