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); % or NaN(1, 10), ones(1, 10) depends with what you want to init V
V(1) = Vi; % initialize V(1) to Vi scalar value
Sorry to not be able to help more, but I don't know what you expect to have into V.