Why does .gt return a vector for simple comparison of two numbers?

조회 수: 1 (최근 30일)
Don
Don 2015년 10월 15일
댓글: Walter Roberson 2015년 10월 16일
The problem: Trying to count heart rate. I have a (somewhat noisy) signal vector of length 30K or so and intend to analyze peak-to-peak times using the nearest-neighbor approach described in the tutorial
This approach reads the data into sig(k), establishes a “cutoff” value, searches for peaks that are greater than the two nearest neighbors AND exceed a cutoff threshold.
Example data:
sig(6)= 385.9312
sig(7) = 406.9276
sig(8) = 257.9995
cutoff = 600
WHY does this occur??
sig(7)>cutoff
ans = 1 1 1
Here’s the code:
j=1;
PtoP=[];
beat_count = 0;
for k = 2:length(sig)-1
if sig(k)>cutoff;
if(sig(k)>sig(k-1));
if(sig(k)>sig(k+1));
beat_count=beat_count+1;
PtoP(j)=k;
j=j+1;
end;
end;
end;
end;
MANY THANKS for any help here
  댓글 수: 1
Star Strider
Star Strider 2015년 10월 15일
I can’t reproduce that. When I copy sig(6:8) to my workspace and execute:
sig(7)>cutoff
ans =
0

댓글을 달려면 로그인하십시오.

채택된 답변

Don
Don 2015년 10월 16일
I don't think I am dealing with 3-element vectors k
k =
31231
>> sig(k)
ans =
-263.9811
>> cutoff
cutoff =
600
>> beat_count
beat_count =
3288
>> sig(k)>cutoff
ans =
0 0 0
  댓글 수: 2
Don
Don 2015년 10월 16일
k
k =
31231
>> sig(k)
ans =
-263.9811
>> cutoff
cutoff =
600
>> beat_count
beat_count =
3288
>> sig(k)>cutoff
ans =
0 0 0
Guillaume
Guillaume 2015년 10월 16일
One possibility is that you've shadowed the comparison operator with a local function or variable. What does
which gt
return ?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Steven Lord
Steven Lord 2015년 10월 16일
I predict that if you check the class of the variable cutoff, it is of class char not a numeric class.
c = '600'
c will be displayed as 600, but it is in fact a vector of 3 characters, '6', '0', and '0'. When you convert cutoff into a number using STR2NUM or similar, you should receive a scalar result from sig(k)>cutoff.
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 10월 16일
Good catch, Steven. The spacing of the result supports that hypothesis. If the 600 had been numeric there would have been spaces before the digits.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2015년 10월 16일
If you have
sig(7)>cutoff
returning a vector of 3 values, then your cutoff must have become a vector of 3 values.
And if
sig(k)>cutoff
returns a vector of 3 values, then either your cutoff has become a vector of 3 values or else your k has become a vector of 3 values.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by