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 ?
Calling <= or le for non-symbolic A and B invokes the MATLAB® le function. This function returns a logical array with elements set to logical 1 (true) where A is less than or equal to B ; otherwise, it returns logical 0 (false) . If both A and B are arrays, then these arrays must have the same dimensions.
M = min( A ) returns the minimum elements of an array. If A is a vector, then min(A) returns the minimum of A . If A is a matrix, then min(A) is a row vector containing the minimum value of each column of A .
M = mean( A ) returns the mean of the elements of A along the first array dimension whose size does not equal 1. If A is a vector, then mean(A) returns the mean of the elements. If A is a matrix, then mean(A) returns a row vector containing the mean of each column.
The easiest way to remove a row or column from a matrix is to set that row or column equal to a pair of empty square brackets [] .
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));
Say your array is x, then you can do it as follows:
x = x(x >= mean(x))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With