Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Pankaja Tanjore
Pankaja Tanjore 2015 年 2 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.

回答 (1 件)

Jos (10584)
Jos (10584) 2015 年 2 月 21 日
Take a look at logical indexing. In pseudocode
TF = A > xxx % logical vector
A(TF) = [] % logical indexing
B(TF) = []
  3 件のコメント
Image Analyst
Image Analyst 2015 年 2 月 21 日
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.
Guillaume
Guillaume 2015 年 2 月 21 日
A search in the doc would give you all the explanation you need about logical indexing.

Community Treasure Hunt

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

Start Hunting!

Translated by