Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 2 (최근 30일)
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.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by