フィルターのクリア

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

2 ビュー (過去 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.

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by