Counting values between values in array

6 visualizaciones (últimos 30 días)
g
g el 29 de Sept. de 2019
Editada: KALYAN ACHARJYA el 29 de Sept. de 2019
I have a variable, call it var, containing thousands of rows of numbers, like so:
123
124
125
128 % some values skipped
129
130
132
% etc
I want to give two values, then count the number of values in the data between (and including) these two values.
For example, if I gave A = 123, B = 129, then I would want it to count in the data and return an output of 5.
I also want to be able to give values that are skipped (though they wouldn't be counted). For example, if I gave A=126 and B=128, I would want an output of 1. Or if I gave A = 128 and B = 131, then I would want an output of 3.
How could this be done? I would like to to be done quickly, because the values reach into the hundreds of thousands.

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 29 de Sept. de 2019
Editada: KALYAN ACHARJYA el 29 de Sept. de 2019
A=123;
B=129;
result=sum(find(var==A | var==B))

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by