MATLAB: Confusion related to ‘for’ loop.

cellcell arraycell arraysforfor looploopmatrixmatrix arraymatrix manipulation

epsilon = 2
p = cell(1,8);
for i = 1:8
p{i} = epsilon
end
How to edit this code so that I can get p{1} = epsilon,p{2} = epsilon ^2 ,p{2} = epsilon ^3 …….
i.e i want p{1} = 2,p{2} = 4, p{3} =8…..
Thanks

Best Answer

p = num2cell(2.^(1:8))