How to display 1D vector with indices into a function
1 次查看(过去 30 天)
显示 更早的评论
I have created a function that identifies the peaks in an ECG over a particular threshold and plots it onto a graph. I would also want the function to display a 1D vector containing the indicies for each of the local maxima (there are 11) that are above the threshold. I have tried the fprintf way but have had no luck. The vector should display these values:
This is the function that id like to incorportate it into (the threshold = 100):
0 个评论
回答(1 个)
KALYAN ACHARJYA
2020-1-11
编辑:KALYAN ACHARJYA
2020-1-12
Store those index in some 1 D array and later call the respective index data from ECG data, see the modified code, you may get idea (modification may be required as per desired result)
function [threshold] = LocalMaxThreshold(thres)
ECG = load('ECG.csv');
threshold = thres;
f_s = 350; %Frequency of ECG [Hz]
n=length(ECG);
t = [0:n-1]/f_s; %Number of samples divided by frquency
idx=[]; l=1;
for k=2:length(ECG)-1
if (ECG(k)>ECG(k-1) && ECG(k) > ECG(k+1) && ECG(k) > threshold) % check the condition carefully
idx(l)=k;
l=l+1;
end
end
plot(t,ECG,'b-',t(idx),ECG(idx),'r*')
2 个评论
KALYAN ACHARJYA
2020-1-12
编辑:KALYAN ACHARJYA
2020-1-12
function [threshold] = LocalMaxThreshold(thres)
ECG = load('ECG.csv');
threshold = thres;
f_s = 350; %Frequency of ECG [Hz]
n=length(ECG);
t = [0:n-1]/f_s; %Number of samples divided by frquency
idx=[]; l=1;
for k=2:length(ECG)-1
if (ECG(k)>ECG(k-1) && ECG(k) > ECG(k+1) && ECG(k) > threshold) % check the condition carefully
idx(l)=k;
l=l+1;
end
end
idx
plot(t,ECG,'b-',t(idx),ECG(idx),'r*')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!