필터 지우기
필터 지우기

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 CenterFile Exchange에서 2-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