How do i plot maximum values

3 views (last 30 days)
Ken Chi
Ken Chi on 9 Jan 2020
Edited: Ken Chi on 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?

Accepted Answer

Turlough Hughes
Turlough Hughes on 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

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!