Finding x for when y equals a certain value
4 views (last 30 days)
Show older comments
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)
0 Comments
Accepted Answer
Wayne King
on 7 Jun 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)
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!