hi.... i have a problem in my code in matlab
i plot my diagram (ECG ) that i get info from database in this site:http://www.physionet.org/ with
now i have ECG diagram in matlab but i want to find value and position of max and min OF ALL OF WAVE ....but with this code i found just one min and one max and i dont know how i can write a loop or for to search and find whole Min and Max of wave with their values in axes y ... in medical field i mean find R-peaks in EKG
thanks alot and my code
x = load ('C:\ekg\example_ecg.txt');
y = x ( : , 2);
h = plot (y );
x = get(h,'XData'); % Get the plotted data
y = get(h,'YData');
imin = find(min(y) == y);% Find the index of the min and max
imax = find(max(y) == y);
text(x(imin),y(imin),[' Min ',num2str(y(imin))],...
'VerticalAlignment','middle',...
'HorizontalAlignment','left',...
'FontSize',7)
text(x(imax),y(imax),['Max ',num2str(y(imax))],...
'VerticalAlignment','bottom',...
'HorizontalAlignment','right',...
'FontSize',7)
If you need to get extrema on the y variable, you can do smth like following.
deriv = diff(y)./x(1:end-1) % numerical derivation, function diff generates array which is one element shorter than initial one.
for i = 2:length(deriv)
if deriv(i-1)*deriv(i) < 0 % i.e. signs are different,
fprintf(1, 'Extremum in point (%f, %f)\n', x(i), y(i))
end
end
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!