Matlab, remove elements from array which are less than average?

Zalaboza picture Zalaboza · Jan 9, 2012 · Viewed 26.9k times · Source

Hi I have a problem writing this with Matlab. So

Situation : array contains (100, 90, 80, 4, 2, 200) for example. I want to calculate the average of these numbers and after that, only keep numbers that are equal to or larger than the average.

Can someone tell me how it can be done ?

Answer

Nzbuu picture Nzbuu · Jan 9, 2012

Personally, I prefer

x(x < mean(x)) = [];

since it makes it clear that you are removing elements from an array, rather than creating an array with a subset of the elements that happens to have the same name.

Note that, on average, there should be no performance difference between this and

x = x(x >= mean(x));