out = x.^y; in matlab

To perform element-wise power operation in Matlab, we use the power operator .^. Here's how to use it to perform the operation out = x.^y:

main.m
x = [1, 2, 3];
y = [2, 3, 4];
out = x.^y;
42 chars
4 lines

This raises each element of the x array to the corresponding power in the y array, and returns an array of the same size as x and y. The resulting out array would be:

main.m
out =
     1     8    81
25 chars
3 lines

If x and y were matrices of the same size, then the power operation would be performed element-wise as well.

gistlibby LogSnag