Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Don
Don le 15 Oct 2015
Commenté : Walter Roberson le 16 Oct 2015
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 commentaire
Star Strider
Star Strider le 15 Oct 2015
I can’t reproduce that. When I copy sig(6:8) to my workspace and execute:
sig(7)>cutoff
ans =
0

Connectez-vous pour commenter.

Réponse acceptée

Don
Don le 16 Oct 2015
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 commentaires
Don
Don le 16 Oct 2015
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 le 16 Oct 2015
One possibility is that you've shadowed the comparison operator with a local function or variable. What does
which gt
return ?

Connectez-vous pour commenter.

Plus de réponses (2)

Steven Lord
Steven Lord le 16 Oct 2015
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 commentaire
Walter Roberson
Walter Roberson le 16 Oct 2015
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.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 16 Oct 2015
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.

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by