How to display 1D vector with indices into a function

조회 수: 2 (최근 30일)
Ken Chi
Ken Chi 2020년 1월 11일
편집: Ken Chi 2020년 1월 12일
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):

답변 (1개)

KALYAN ACHARJYA
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
Ken Chi
Ken Chi 2020년 1월 12일
That worked but gave me the idx as it worked out each in the commant window which cluttered the command window . Is there a way of just displaying all of them at once in the command window in 1-2 rows?
KALYAN ACHARJYA
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 CenterFile Exchange에서 Signal Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by