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)

 採用された回答

Wayne King
Wayne King 2012 年 6 月 7 日

1 投票

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)

1 件のコメント

Rekesh
Rekesh 2012 年 6 月 7 日
thank you that works extremely well

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by