Why does .gt return a vector for simple comparison of two numbers?
1 view (last 30 days)
Show older comments
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
Heartrate (BPM) Example Matlab Code | dadorran https://dadorran.wordpress.com/2014/05/22/heartrate-bpm-example-matlab-code/
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 Comment
Star Strider
on 15 Oct 2015
I can’t reproduce that. When I copy sig(6:8) to my workspace and execute:
sig(7)>cutoff
ans =
0
Accepted Answer
More Answers (2)
Steven Lord
on 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 Comment
Walter Roberson
on 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.
Walter Roberson
on 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.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!