Q:

Vectorize the following code. Write statement(s) that accomplish the same thing, eliminating the loop. Assume that there is a vector v that has a negative number in it, e.g:

0

Vectorize the following code. Write statement(s) that accomplish the same thing, eliminating the loop. Assume that there is a vector v that has a negative number in it, e.g:

>> v = [4 11 22 5 33 -8 3 99 52];

All Answers

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

newv = [ ];

i = 1;

while v(i) >= 0

 newv(i) = v(i);

 i = i + 1;

end

newv % Note: just to display

where = find(v < 0);

newv = v(1:where-1)

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