MATLAB Answers

0

how to multiply a row with 1st and 2nd row of a matrix seperately

Asked by Panda Girl on 8 Dec 2018 at 21:32
Latest activity Answered by Star Strider
on 8 Dec 2018 at 21:55
>> y_0
y_0 =
0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1
>> z
z =
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0
I am trying to multiply y_0 with row 1 of z and row 2 of z. but I am not sure how
i tried :z and z: but its giving errors. Kindly help

  1 Comment

xor(y_0 with row1 of z)
and xor(y_0 with row 2 of z)

Sign in to comment.

2 Answers

Answer by Cris LaPierre on 8 Dec 2018 at 21:54

If you are new to MATLAB, I'd suggest MATLAB Onramp. Chapter 6 talks about performing calculations with arrays.

  0 Comments

Sign in to comment.


Answer by Star Strider
on 8 Dec 2018 at 21:55

One option is to use the bsxfun (link) function:
y_0 = [0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1];
z = [1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0];
Out = bsxfun(@xor, y_0, z)
producing:
Out =
2×16 logical array
1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

  0 Comments

Sign in to comment.