How do i plot maximum values

1 次查看(过去 30 天)
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?

采纳的回答

Turlough Hughes
Turlough Hughes 2020-1-9
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by