How to determine the mean of certain y values ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Niklas Kurz
el 16 de Mayo de 2020
Comentada: Star Strider
el 17 de Mayo de 2020
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.
0 comentarios
Respuesta aceptada
Star Strider
el 16 de Mayo de 2020
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!