Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Find the mean value and an array and then eliminate the value from an array which is greater than mean

2 visualizzazioni (ultimi 30 giorni)
Hello,
I have an array A=[50;20;50;70;30]; and B=[60;10;30;40]; Now I find the mean of array using the function mean.
Mean_A=mean(A);
I get
Mean_A=44
Now I go to the Array A=[50;20;50;70;30]; and check for the elements whose values are greater the mean value. Now in the array A I have first element as 50 which is greater than 44.So I will remove this element from A. After this I go to the second array B=[60;10;30;40];and remove the 1st element from the array B which is 60 irrespective of what the value is, as the 1st element is removed in A. Similarly I check for 2nd element in A which is 20, now 20 is lesser than 44 so it is not removed. Now go to third element of A which is equal to 50. Now 50 is greater than mean =44 so remove this element from A. Now go to the second array B and remove the 3rd element from B irrespective of what the value is.
Please let me know the function MATLAB to do this.
Let me know if the question is clear. Let me know any more information is required.
Looking forward to hear from you Thanks.

Risposte (1)

Jos (10584)
Jos (10584) il 21 Feb 2015
Take a look at logical indexing. In pseudocode
TF = A > xxx % logical vector
A(TF) = [] % logical indexing
B(TF) = []
  3 Commenti
Image Analyst
Image Analyst il 21 Feb 2015
xxx should have been Mean_A. TF is a logical vector (true or false) that says whether each index is greater than Mean_A or not. With logical indexes, only the "true" ones are used in the operation. So A(TF) means that indexes that are > Mean_A will be set to [], which is null and which means that those elements will be removed/deleted from the array A.
Please mark the answer as "Accepted" to give Jos reputation points.

Questa domanda è chiusa.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by