Q:

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):

0

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):

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now