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:
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:5| Question number:30.5
All Answers
total answers (1)
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