I need to compute E{x^4} in MatLab (x is vector). Can it be done by taking the mean value of x^4 (each element of x exponent 4).
Thanks for the help. Regards
Best Answer
Many basic operators in MATLAB are treated as matrix operations, includingmultiplication ,division ,andpower operators.
When you wish to perform the same operation element-wise, then you can use the element-wise syntax. For example matrix multiplication isA*B, whereasmultiplication of corresponding array elements isA.*B .
In your example, this means you can simply use theelement-wise power function:
x.^4
which operates on the whole vector at once. Handy! You might like to read this too:
Since 'x' is a vector, the '.' operator should be applied for performing division. The '.' operator will perform the operation on each element of the vector. The code will look like:
Best Answer