matlab求拟合优度,即R

function[r]=formular1(y1,y2)
    %y1为真实值,y2为拟合值
    mean_y1 = mean(y1);
    sum_y1 = 0;
    sum_y2 = 0;
    size = length(y1);
    for i = 1:size
        sum_y1 = (y2(i)-mean_y1)^2+sum_y1;
        sum_y2 = (y1(i)-mean_y1)^2+sum_y2;
    end
    r = sum_y1/sum_y2;
end
%记得自己输出r,r越接近于1拟合度越高

你可能感兴趣的:(matlab,拟合优度,matlab)