フィルターのクリア

How to determine the mean of certain y values ?

3 ビュー (過去 30 日間)
Niklas Kurz
Niklas Kurz 2020 年 5 月 16 日
コメント済み: Star Strider 2020 年 5 月 17 日
This may sound like a genuinely easy question, but I'm quite a newbie.
So far I imported values from a .txt file (A = readtable) and seperated: x = A{:,1}; and y = A{:,3}; in order to plot it. For whatever reason I'd like the mean of some y values to be computed. I tried: ind = y>= ... & <= ... followed by mean(ind), but it didn't work properly. It'd be most kind if you could show me how to perform this mere calculation correctly.
Kind Regards.

採用された回答

Star Strider
Star Strider 2020 年 5 月 16 日
It would be helpful to see all the relevant code.
However on the basis of what you posted, taking the mean of ‘ind’ is going to take the mean of the logical vector, so the result is going to be between 0 and 1, since logical values become numeric when used in other numeric calculations. The calculation of ‘ind’ may also not be correct, although the full code for it is not presented.
Try this:
A = sortrows(rand(25,3),1); % Create ‘A’
x = A(:,1);
y = A(:,2);
ind = y >= 0.4 & y <= 0.6;
yindmean = mean(y(ind));
That should do what you want.
  2 件のコメント
Niklas Kurz
Niklas Kurz 2020 年 5 月 17 日
編集済み: Niklas Kurz 2020 年 5 月 17 日
Thank you for your Answere! I figured
mean(y(1:120))
also works just fine. Kind regards.
Star Strider
Star Strider 2020 年 5 月 17 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by