You can do it with a double loop
Orig = [xyzk]; exponent = [0 1 2 3 4 5]; %# preassign output to speed up loop output = zeros(length(Orig),length(exponent)); %# loop over all elements in Orig for r = 1:length(Orig) %# loop over all exponents for c = 1:length(exponent) output(r,c) = Orig(r)^exponent(c); end end
However, this is not the case as you usually program in Matlab.
Instead, you replicate both Orig and exponent , and perform the calculations in a single, vectorized operation:
%
For several years there was a short version for this, using the bsxfun function. This will automatically execute the extension we made above with repmat , and it will be faster.
output = bsxfun(@power, Orig', exponent);
Jonas source share