user131983
user131983

Reputation: 3937

Matlab: Deleting elements from a vector

I am not sure why the code below doesn't work. I'm basically trying to get rid of elements in probofdetectionanddelamprop that are equal to 1 or are less than 10e-12, which means that the size of probofdetectionanddelamprop is changing dynamically. I therefore added a while loop to check when i equals the new size(probofdetectionanddelamprop), but this does not appear to be working.

while i ~= numel(probofdetectionanddelamprop)
for i = 1:no_iterations % Clearly, no_iterations is > numel(probofdetectionanddelamprop)
    if (probofdetectionanddelamprop(i) <=10e-12 || probofdetectionanddelamprop(i) == 1)
        probofdetectionanddelamprop(i) = [];     
    end
end
end

Thanks

Upvotes: 1

Views: 48

Answers (1)

shaoyl85
shaoyl85

Reputation: 1964

How about this:

probofdetectionanddelamprop(probofdetectionanddelamprop < 1e-11 | probofdetectionanddelamprop == 1) = [];

Upvotes: 3

Related Questions