How do i plot maximum values

1 vue (au cours des 30 derniers jours)
Ken Chi
Ken Chi le 9 Jan 2020
Modifié(e) : Ken Chi le 12 Jan 2020
I am writing a function to plot all the maximum values of a 1D matrix on a graph. When i click 'Run', no figure shows up and the command window just displays all the figures of the 1D matrix. what am i doing wrong?

Réponse acceptée

Turlough Hughes
Turlough Hughes le 9 Jan 2020
You weren't actually calling the function. Secondly, the function had no input argument for threshold so I've included that. I also removed the loop as it simplifies the code and makes it more efficient.
ECG = load('ECG.csv');
f_s = 350; %Frequency of ECG [Hz]
Time = (0:length(ECG)-1)/f_s; %Number of samples divided by frquency
Amp = ECG(:,1); %ECG Amplitude
threshold = 100;
figure(), plot(Time,Amp,'b-') % I've pulled this out of the function
[Time_peak, Amp_peak] = findLocalMaxThreshold(Time,Amp,threshold)
hold on; plot(Time_peak, Amp_peak, '*r')
function [xp,yp] = findLocalMaxThreshold(x,y,threshold)
idx = find(y(2:end-1) > (y(1:end-2)) & y(2:end-1) > y(3:end) & y(2:end-1) > threshold ) + 1;
xp = x(idx);
yp = y(idx);
end

Plus de réponses (0)

Catégories

En savoir plus sur Denoising and Compression dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by