dydx = gradient(y) ./ gradient(x);
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0);
zxidx = zci(dydx);
for k1 = 1:numel(zxidx)
ixrng = max(zxidx(k1)-2,1):min(zxidx(k1)+2,numel(x));
inflptx(k1) = interp1(dydx(ixrng), x(ixrng), 0, 'linear');
inflpty(k1) = interp1(x(ixrng), y(ixrng), inflptx(k1), 'linear');
end
figure(1)
plot(x, y)
hold on
plot(x, dydx*10)
plot(inflptx, inflpty, 'pg', 'MarkerFaceColor','g')
hold off
grid
legend('Data', 'Derivative', 'Inflection Points', 'Location','best')
inflpts = sprintfc('(%5.3f,%5.3f)', [inflptx; inflpty].');
text(inflptx, inflpty, inflpts,'FontSize',8, 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
Best Answer