How to find the up-crossing of graph
3 ビュー (過去 30 日間)
古いコメントを表示
Hey,
I have produced a graph with surface elevation of a water wave against time, this is shown in the following picture:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161639/image.png)
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
0 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Directed Graphs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!