实例1:
现已知两组数据:
x=[1 2 3 4 5 6 7 8 9];
y=[2 10 26 37 81];
目的:作出y关于x的曲线图形
程序:
x=1:9;
y=[2 10 26 37 81];
f=polyfit(x,y,2)
x0=1::9;
y0=polyval(f,x0);
plot(x,y,'*',x0,y0);
xlabel('横坐标x')
ylabel('纵坐标y')
title('描点绘制曲线')
legend('描点坐标','绘制的曲线')
grid off
实例2:
matlab 如何画图时将数据点的值在图中显示出来可以用text在图上写字符串,例如
clear
clc
x=[1 2 3 4 5];
y=[3 6 10 16 20];
str=[repmat(' X:',5,1) num2str(x') repmat(', Y:',5,1) num2str(y')];
plot(x,y,'-o')
text(x,y,cellstr(str))