How to find the up-crossing of graph

조회 수: 6 (최근 30일)
Oliver Goldsmith
Oliver Goldsmith 2017년 3월 13일
답변: Star Strider 2017년 3월 13일
Hey,
I have produced a graph with surface elevation of a water wave against time, this is shown in the following picture:
Is there a matlab function or way of reading the graph so that when Y=0 x=? and only output data when Y is going from negative to positive ie. when the line is up-crossing the x-axis? This will give me the period of the wave.
Unfortunately the data itself doesn't have y=0 it merely swaps from positive to negative and hence why reading it from the graph is necessary
Thank you for your time,
Oliver

답변 (1개)

Star Strider
Star Strider 2017년 3월 13일
I have a little utility function that I wrote for just that purpose:
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
Because it can produce a false zero-crossing at the end of the vector, it may be necessary to discard the last index it returns.
To find the ‘exact’ zero-crossings from the indices it returns, a for loop and interp1 is the easiest way.
Example:
idx_vct = zci(your_y_data);
for k1 = 1:length(idx_vct)
idx_rng = (idx_vct(k1)-1:idx_vct(k1)+1);
x_zero(k1) = interp1(y(idx_rng), x(idx_rng), 0);
end
Note This is UNTESTED CODE. It should work, but may require modification. Be certain that ‘idx_vct(k1)-1’ and ‘idx_vct(k1)+1’ do not over-write the vector.

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by