How to find out if a curve passes through zero and goes from positive to negative value?

18 ビュー (過去 30 日間)
joynob ahmed
joynob ahmed 2020 年 7 月 12 日
コメント済み: joynob ahmed 2020 年 7 月 15 日
Hi.I have divided this curve:
into 8 region where the points of 1st 1/8 portion is in x=1,2nd portion in x=2 etc like this:
Now I want to find out if there is a code by which for x=1,2,3,4,5,6,7,8 if there is zero crossing and points changing from positive to negative value.Hope you understand.Thank you in advance.
My code is this:
j=diff(I);
figure
plot(j);
n = 8 ;
d=j';
a=length(j);
% check whether data needed to be appended to reshape into n
b = n * ceil(a / n)-a ;
%
d = [d NaN(1,b)] ;
iwant = reshape(d,[],n);
% plot
figure
plot(iwant','b*')
  3 件のコメント
joynob ahmed
joynob ahmed 2020 年 7 月 13 日
fzero doesn't work here showing the error:
''FUN must be a function, a valid character vector expression, or an inline function object''
joynob ahmed
joynob ahmed 2020 年 7 月 13 日
If I write this for the image
x0=[0 1];
if fzero(iwant',x0)==true
B1=1
else
B1=0
end
Same error is shown. Can't I do this for x=1,2,3.... in seperate code in the same way? Then my code will be easier for me.

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

回答 (1 件)

Image Analyst
Image Analyst 2020 年 7 月 12 日
A single value cannot "change" sign or "cross the axis". Chances are that none of the y values where x = 0, 2, 4, ... are EXACTLY zero. So you need to look at x and find which ones are above the axis and which are below. You can then determine where the value went from - to + or vice versa.
y = rand(1, 20) - 0.5
s = sign(y)
% Find first index of the two where the crossing occurs.
positiveGoingIndexes = strfind(s, [-1, 1])
negativeGoingIndexes = strfind(s, [1, -1])
If you need more help, please attach "I" (poor name by the way) in a mat file with the paper clip icon.
  10 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 14 日
Where did you show that error? I looked above and am not seeing it.
And I ran your latest attached code and it ran without error, though it did not have strfind() in it anywhere so it doesn't look like you took my suggestion.
And I still think looking for zero crossings of the derivative is not needed.
joynob ahmed
joynob ahmed 2020 年 7 月 15 日
I have used it but it didn't give correct result. I have wrote this:
negativeGoingIndexes = strfind(region3, [1, -1])
where the image is :
But the result is:
negativeGoingIndexes =
[]
whereas you can see there are many negative going points.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by