Vectorize this code! Write one assignment statement that will accomplish exactly the same thing as the given code (assume that the variable vec has been initialized):
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:5| Question number:27.5
All Answers
total answers (1)
newv = zeros(size(vec));
myprod = 1;
for i = 1:length(vec)
myprod = myprod * vec(i);
newv(i) = myprod;
end
newv % Note: this is just to display the value
>> newv = cumprod(vec)
need an explanation for this answer? contact us directly to get an explanation for this answer