2024年4月1日发(作者:毋思山)
1. 常规绘图数据提取
(1)首先随便设定一些点,然后绘制一条曲线:
Z = peaks;
h = plot(Z(:,33));
(2)然后提取曲线上的点,找到这些点中的最值并标注:
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),[' Minimum = ',num2str(y(imin))],...
'VerticalAlignment','middle',...
'HorizontalAlignment','left',...
'FontSize',14)
text(x(imax),y(imax),['Maximum = ',num2str(y(imax))],...
'VerticalAlignment','bottom',...
'HorizontalAlignment','right',...
'FontSize',14)
4
Maximum = 3.254
3
2
1
0
-1
-2
-3
Minimum = -2.7633
35404550
2. 隐函数绘图只有一个变量数据提取
>> subplot(211)
>> h=ezplot('cos(x)');
>> hold on
>> x=get(h,'xdata');
>> y=get(h,'ydata');
>> subplot(212)
>> plot(x,y,'*r')
>> axis([-2*pi 2*pi -1 1])
>>
cos(x)
1
0.5
0
-0.5
-1
-6-4-20
x
246
1
0.5
0
-0.5
-1
-6-4-20246
3. 隐函数绘图有2个变量数据提取
>> subplot(211)
>> h=ezplot('x^2-y^4');
>> C=get(h,'contourMatrix');
>> a=C(1,1),b=C(2,1)
a =
0
b =
344
>> x1=C(1,2:345);x2=C(1,347:690);
>> y1=C(2,2:345);y2=C(2,347:690);
>> subplot(212)
>> plot(x1,y1,x2,y2)
>> axis([-2*pi 2*pi -2*pi 2*pi])
>>
观察矩阵C,可以看出第一列数据C(:,1)是0和344;而且仔细查看矩阵C,可以发现,
2024年4月1日发(作者:毋思山)
1. 常规绘图数据提取
(1)首先随便设定一些点,然后绘制一条曲线:
Z = peaks;
h = plot(Z(:,33));
(2)然后提取曲线上的点,找到这些点中的最值并标注:
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),[' Minimum = ',num2str(y(imin))],...
'VerticalAlignment','middle',...
'HorizontalAlignment','left',...
'FontSize',14)
text(x(imax),y(imax),['Maximum = ',num2str(y(imax))],...
'VerticalAlignment','bottom',...
'HorizontalAlignment','right',...
'FontSize',14)
4
Maximum = 3.254
3
2
1
0
-1
-2
-3
Minimum = -2.7633
35404550
2. 隐函数绘图只有一个变量数据提取
>> subplot(211)
>> h=ezplot('cos(x)');
>> hold on
>> x=get(h,'xdata');
>> y=get(h,'ydata');
>> subplot(212)
>> plot(x,y,'*r')
>> axis([-2*pi 2*pi -1 1])
>>
cos(x)
1
0.5
0
-0.5
-1
-6-4-20
x
246
1
0.5
0
-0.5
-1
-6-4-20246
3. 隐函数绘图有2个变量数据提取
>> subplot(211)
>> h=ezplot('x^2-y^4');
>> C=get(h,'contourMatrix');
>> a=C(1,1),b=C(2,1)
a =
0
b =
344
>> x1=C(1,2:345);x2=C(1,347:690);
>> y1=C(2,2:345);y2=C(2,347:690);
>> subplot(212)
>> plot(x1,y1,x2,y2)
>> axis([-2*pi 2*pi -2*pi 2*pi])
>>
观察矩阵C,可以看出第一列数据C(:,1)是0和344;而且仔细查看矩阵C,可以发现,