In Matlab I am trying to assign values of a variable generated within a for-loop to an array.
for i=1:4
S = 2*i;
P(i) = S;
end
S is generated within the for loop and all the values it will have are: 2, 4, 6 and 8.
Now I want to assign each of these values of S to an array P such that I want
P(1) = 2, P(2) = 4, P(3) = 6, P(4) = 8
But the for-loop I have included does not work and I have no idea why. First of all it creates a char rather than creating and array. Secondly, none of the values are added and at the end P is empty.
I am not sure why its not working? Does anybody know how to fix this?
P=zeros(4,1);