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.
0 个评论
回答(1 个)
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
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
2015-2-21
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!