MATLAB Answers

could anyone help me to display the values in the matrix which are greater than the average value for the following code

1 ビュー (過去 30 日間)
jaah navi
jaah navi 2019 年 12 月 4 日
コメント済み: jaah navi 2019 年 12 月 4 日
code:
A=[3.3734 5.1245 4.3729 2.8406 6.5283 4.8144 2.9305 6.8098 2.8633 4.2790 6.3190 5.7503 5.4061 6.0009 9.3549]
B=sum(A)
C=numel(A)
D=B/C
When i run the code the value of D is found to be 5.1179
so i want to display A such that the values present in A should be greater than 5.1179 and hence
A = [5.1245 6.5283 6.8098 6.3190 5.7503 5.4061 6.0009 9.3549]
could anyone please help me on this.

  0 件のコメント

サインイン to comment.

採用された回答

Stephan
Stephan 2019 年 12 月 4 日
編集済み: Stephan 2019 年 12 月 4 日
B, C and D are not needed, if you use the inbuilt function mean:
A=[3.3734 5.1245 4.3729 2.8406 6.5283 4.8144 2.9305 6.8098 2.8633 4.2790 6.3190 5.7503 5.4061 6.0009 9.3549]
A = A(A>mean(A))
results in:
A =
Columns 1 through 8
3.3734 5.1245 4.3729 2.8406 6.5283 4.8144 2.9305 6.8098
Columns 9 through 15
2.8633 4.2790 6.3190 5.7503 5.4061 6.0009 9.3549
A =
5.1245 6.5283 6.8098 6.3190 5.7503 5.4061 6.0009 9.3549

  1 件のコメント

jaah navi
jaah navi 2019 年 12 月 4 日
with respect to the above code the mean(A) is 5.1179
so I need to select the values which are greater than 5,which means values from 6 - 6.5283 6.8098 6.3190 6.0009 and values from 9-9.3549 should be selected.
Could you please help me on this.

サインイン to comment.

その他の回答 (1 件)

Inho Kim
Inho Kim 2019 年 12 月 4 日
Hi Jaah,
You can use logical index.
ind = A > D; % find indices when each value of A is bigger than D
AA = A(ind); % extract element from A vector
Thanks,
Inho

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。


Translated by