Base on your code, I see that at line 13 of ProgramCd, you create V as a scalar because you even ensure that Vi must be of size 1.
If you want to have a vector V of e.g. 10, than:
V = zeros(1, 10);
V(1) = Vi;
Sorry to not be able to help more, but I don't know what you expect to have into V.