How to display 1D vector with indices into a function

2 visualizaciones (últimos 30 días)
Ken Chi
Ken Chi el 11 de En. de 2020
Editada: Ken Chi el 12 de En. de 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):

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 11 de En. de 2020
Editada: KALYAN ACHARJYA el 12 de En. de 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 comentarios
Ken Chi
Ken Chi el 12 de En. de 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 el 12 de En. de 2020
Editada: KALYAN ACHARJYA el 12 de En. de 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*')

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by