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

1 次查看(过去 30 天)
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

采纳的回答

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