Detecting change in sign of values of a column

6 ビュー (過去 30 日間)
jacob Mitch
jacob Mitch 2019 年 11 月 12 日
編集済み: Adam 2019 年 11 月 12 日
If I a data file with 3 columns the first being the x cordinates second being the y cordinates and the third being the z.
Data(:,2); %produces all the y values which are +-0.1 either side of y=0
So If I have
Data(:,2)=[0.03;0.05;0.08;-0.01;-0.05;-0.06;0.02;0.03; -0.05;-0.01]
%^sign change %^sign change ^^sign change
%so must pass %so must pass
%y=0 %y=0
How would I run a loop that goes through Data(:,2) and finds where the y values have changed sign and stores that position. So in my example it would detect the first change in sign from 0.08 to -0.01 (4th position of -0.01) the second change in sign at-0.06 and 0.02 (7th position of 0.02) the third sign change at 0.03 -0.05 (9th position of -0.05) which shows they have passed through y=0 and store those positions as a new column
NewC=[4;7;9];
I hope that makes sense and any help would be appreciated .

採用された回答

Adam
Adam 2019 年 11 月 12 日
編集済み: Adam 2019 年 11 月 12 日
NewC = find( diff( sign( Data(:,2) ) ) ) + 1;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by