How do i plot maximum values

조회 수: 3 (최근 30일)
Ken Chi
Ken Chi 2020년 1월 9일
편집: Ken Chi 2020년 1월 12일
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에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by