How to display 1D vector with indices into a function

3 vues (au cours des 30 derniers jours)
Ken Chi
Ken Chi le 11 Jan 2020
Modifié(e) : Ken Chi le 12 Jan 2020
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):

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 11 Jan 2020
Modifié(e) : KALYAN ACHARJYA le 12 Jan 2020
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 commentaires
Ken Chi
Ken Chi le 12 Jan 2020
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 le 12 Jan 2020
Modifié(e) : KALYAN ACHARJYA le 12 Jan 2020
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*')

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by