我编写了代码,在我的分散数据上绘制了一个傅里叶级数拟合线,但我不能想如何打印线的方程式, 为了解决我的二次拟合
phi = [ones(NN,1),datax1T,datax1T.^2,datax1T.^3];
我会用
s=sprintf('y=%8f+%8fx+%8fx^2+%8fx^3',aa(1),aa(2),aa(3),aa(4));
这是我的傅立叶拟合线的代码
load('fitdata.mat', 'datax1', 'datay1'); format long
datax1T =(datax1)'; %transpose of the data
datay1T =(datay1)';
k=1;
%Calculate number of data points
NN = length(datax1T);
%Calculate Design Matrix
phi = [ones(NN,1),sin(k*datax1T), cos(k*datax1T), sin(2*k*datax1T), cos(2*k*datax1T)];
%Solve System equations
aa= phi\datay1T;
%Calculate fitted values of y
yfit = phi*aa;
%Plot the output
plot(datax1T, datay1T, 'ro', datax1T, yfit, 'k-');
%Tidy up graph
s=sprintf('y=?????',aa(1),aa(2),aa(3)??); %what to put here?
legend('data',s,,'Location','southeast');
title ('Fourrier Fit Function','FontSize', 20)
xlabel('x data'); ylabel('y data');
答案 0 :(得分:0)
使用'text'怎么样?
sprintf(X,Y, ['y=',aa(1),'+',aa(2),'x+',aa(3)','x^2+',aa(4),'x^3']);
X和Y是您要打印它的坐标