+3 votes
in Programming Languages by (5.4k points)
I want to multiply the corresponding elements of two Matlab arrays and generate a third array as an output. How can do this?

E.g.

a=[2 4 6 8 10]

b=[1 3 5 7 9]

The multiplication of a and b should be [2 12 30 56 90].

1 Answer

0 votes
by (33.7k points)

You can try one of the following approaches highlighted below to multiply the corresponding elements of two Matlab arrays.

>> a=[2 4 6 8 10]
a =
     2     4     6     8    10
>> b=[1 3 5 7 9]
b =
     1     3     5     7     9
>> a.*b
ans =
     2    12    30    56    90
>> times(a,b)
ans =
     2    12    30    56    90

...