matlab中的trendline选项(excel)

Kat*_*tyB 2 excel matlab

在excel中,我记得能够根据文档选择一个称为"power"的特定趋势线:

"功率趋势线是一条曲线,最适合用于比较以特定速率增加的测量值的数据集 - 例如,赛车以一秒钟的间隔加速.如果您的数据包含零值或负值,则无法创建电源趋势线.

我怎样才能在matlab中实现它?

例如:

a = [15.5156,0.1995;
7.6003,0.2999;
9.4829,0.2592;
12.2185,0.2239;
23.4094,0.1811];

figure;scatter(a(:,1),a(:,2))
Run Code Online (Sandbox Code Playgroud)

kol*_*kol 5

是一个有效的解决方案:

a = [15.5156,0.1995;
7.6003,0.2999;
9.4829,0.2592;
12.2185,0.2239;
23.4094,0.1811];

x = a(:, 1);
y = a(:, 2);
n = 2; % order of the fitted polynomial trendline
p = polyfit(x, y, n);
m = 1000; % number of trendline points (the larger the smoother)
xx = linspace(min(x), max(x), m);
yy = polyval(p, xx);

figure;
hold on;
scatter(a(:,1), a(:,2));
plot(xx, yy, 'r-');
Run Code Online (Sandbox Code Playgroud)

您可以轻松地将趋势线计算器代码放入单独的函数中.