MATLAB: Multiplying each value of a vector with the corresponding value in another vector

multiplicationvector

I have 4 vectors E,A,alpha,temp (each 21×1)
I want to carry out the following equation:
theta = E*A*alpha*temp [-1 ;1]
and theta be a vector where the first value is: theta(1) = E(1)*A(1)*alpha(1)*temp(1) * [-1;1]
and theta(n) = E(n)*A(n)*alpha(n)*temp(n) * [-1;1] etc.
Do I use for loop, how would I got about this?
Thank you in advance.

Best Answer

Use element-wise multiplication. If all the other vectors are column vectors, the [-1 1] vector must be a row vector:
theta = E.*A.*alpha.*temp*[-1 1]
See Array vs. Matrix Operations for an explanation.