Write a function remove elt(v,a) that takes as input a vector v and a number a, and as output returns a vector that is the same as v but with a single value of a removed. For example, if we run remove elt([-2 1 3 1 5], 1 ), then the output should be either [-2 3 1 5] or [-2 1 3 5]. matlab question
function result = elt(v,a) result = []; k = 1; alreadyRemoved = false; for i=1:length(v) if(v(i)==a) if(alreadyRemoved==false) alreadyRemoved=true; continue; else result(k)=v(i); k=k+1; end else result(k)=v(i); k=k+1; end end end
Get Answers For Free
Most questions answered within 1 hours.