How to determine the mean of certain y values ?

1 次查看(过去 30 天)
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.

更多回答(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