+3 votes
in Programming Languages by (40.5k 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

+1 vote
by (348k points)
selected by
 
Best answer

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


...