Contents
example of plot and find and mark maximum and minimum values on a plot
Author:
minhanhnguyen@q.com
close
close all;
clear all;
clc;
generate a simple plot
x = linspace(-3,3);
y = (x/5-x.^3).*exp(-2*x.^2);
plot(x,y)
find the mimimum value
indexmin = find(min(y) == y);
xmin = x(indexmin);
ymin = y(indexmin);
strmin = ['Minimum = ',num2str(ymin)];
text(xmin,ymin,strmin,'HorizontalAlignment','left');
find the max value
indexmax = find(max(y) == y);
xmax = x(indexmax);
ymax = y(indexmax);
strmax = ['Maximum = ',num2str(ymax)];
text(xmax,ymax,strmax,'HorizontalAlignment','right');
No comments:
Post a Comment