Finding x for when y equals a certain value

My current problem is that I have a huge set of data for a pressure rise caused by a train entering the tunnel. I would like to find the values of x whenever the pressure rises crosses a pressure threshold and would like to be able to work out the difference between the pair of x's (should only be one pair)

 Respuesta aceptada

Wayne King
Wayne King el 7 de Jun. de 2012
Say x is your x-vector, and I'll let y be your pressure readings, would the following work? I'll make the threshold 2 in this example, but obviously you have to use your value.
y = abs(randn(100,1));
x = 0:99;
index1 = find(y>2,1,'first');
index2 = find(y(index1+1:end)<2,1,'first');
index2 = index2+index1;
x(index2)-x(index1)

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Jun. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by