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:
Combine two matrices

Subject: Combine two matrices

From: Milos Milenkovic

Date: 3 Feb, 2014 09:45:09

Message: 1 of 4

Dear all,
how (for various sizes of A5 and A6) to make matrix A6 in which all rows with zeros are substituted by rows from A5. First and second of A5 are the second and third of A6, Third and fourth of A5 are fifth and sixth of A6, Fifth and sixth of A5 are eighth and ninth of A6.
Thanks in advance!


A5 =
    -1 0 0 0 0 0 0 0 0 0 0 0
     0 -1 0 0 0 0 0 0 0 0 0 0
     0 0 -1 0 0 0 0 0 0 0 0 0
     0 0 0 -1 0 0 0 0 0 0 0 0
     0 0 0 0 -1 0 0 0 0 0 0 0
     0 0 0 0 0 -1 0 0 0 0 0 0
>> A6
A6 =
    -1 -1 0 0 0 0 -1 -1 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0 0
     0 0 -1 -1 0 0 0 0 -1 -1 0 0
     0 0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 -1 -1 0 0 0 0 -1 -1
     0 0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0 0

Subject: Combine two matrices

From: dpb

Date: 3 Feb, 2014 14:03:00

Message: 2 of 4

On 2/3/2014 3:45 AM, Milos Milenkovic wrote:
> Dear all, how (for various sizes of A5 and A6) to make matrix A6 in
> which all rows with zeros are substituted by rows from A5. ...

ix=~all(A6,2);
A6(ix,:)=A5(ix,:);

doc all

Lookup "logical addressing"

--

Subject: Combine two matrices

From: dpb

Date: 3 Feb, 2014 17:14:56

Message: 3 of 4

On 2/3/2014 8:03 AM, dpb wrote:
> On 2/3/2014 3:45 AM, Milos Milenkovic wrote:
>> Dear all, how (for various sizes of A5 and A6) to make matrix A6 in
>> which all rows with zeros are substituted by rows from A5. ...
>
> ix=~all(A6,2);
> A6(ix,:)=A5(ix,:);

...

ERRATUM:

ix=~any(A6,2);

rather than all(), sorry.

--

Subject: Combine two matrices

From: Milos Milenkovic

Date: 3 Feb, 2014 20:04:08

Message: 4 of 4

dear,
great, thank you. Just one notice:
 ix=~any(A6,2);
> > A6(ix,:)=A5(:,:);


dpb <none@non.net> wrote in message <lcoir3$6en$1@speranza.aioe.org>...
> On 2/3/2014 8:03 AM, dpb wrote:
> > On 2/3/2014 3:45 AM, Milos Milenkovic wrote:
> >> Dear all, how (for various sizes of A5 and A6) to make matrix A6 in
> >> which all rows with zeros are substituted by rows from A5. ...
> >
> > ix=~all(A6,2);
> > A6(ix,:)=A5(ix,:);
>
> ...
>
> ERRATUM:
>
> ix=~any(A6,2);
>
> rather than all(), sorry.
>
>
>
>
>
>

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