findpeaks is in the Signal Processing Toolbox. If it is included on your license, you can install it using the Add-Ons Explorer.
The points are captured in variables [pk, loc] and [pkN, locN]. Your question didn't ask how to print them to the screen, but just remove the semicolon at the end fo those lines of code.
Otherwise, your approach is valid. You just need to account for all the points rather than just the first one. Here, I use the 2nd derivative to determine if the point is local min or max.
You will need Symbolic Math Toolbox to use the syms function, but you could use the islocalmin and islocalmax functions from MATLAB instead of findpeaks from Signal Processing Toolbox.
First plot the function and retrieve the coordinate data:
syms x y real
y=abs(x^3-9*x);
h = fplot(y, [-5 5]);
xdata = h.XData;
ydata = h.YData;
Find and plot the local minima. You would repeat these lines but replace islocalmin with islocalmax to find the local maxima.
You need to be careful when using fprintf() with multiple arguments that are non-scalar. fprintf() "consumes" all of the first parameter before moving on to all of the second parameter, and does so "down" columns first. That is why @Cris LaPierre constructed [xminima;yminima] which is two row vectors stacked on top of each other: going "down" the columns is picking out first an x and then a y, then back to the next x and the next y. The code as-is would not work properly if xminima and yminima started out as column vectors.
No, you cannot find intervals of increasing and decreasing with the code posted by @Steven Lord -- not without stripping down to all but the first 5 lines and then adding notable additional code.
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
Translated by
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.