[英]Octave one line two plot differ from multiple line plot
I'm fitting some data, but when I plot the data and fit in one-line-plot (see left figure) the drawn graph is correct我正在拟合一些数据,但是当我 plot 数据并适合单线图(见左图)时,绘制的图是正确的
plot(x, y, '.b;data;', [0.05 2], phi(1)+phi(2)*[0.05 2], '--r;fit;', [0.05 2]);
But when I used two separated plot (see right figure) the graph differs from mention above但是当我使用两个分开的 plot(见右图)时,图表与上面提到的不同
hold on;
plot(x, y, '.b;data;', [0.05 2]);
plot(phi(1)+phi(2)*[0.05 2], '--r;fit;', [0.05 2]);
hold off;
grid on;
Data数据
[x, y]
ans =
0.050000 3571.000000
0.100000 6567.000000
0.200000 12760.000000
0.300000 20512.000000
0.400000 25480.000000
0.500000 32088.000000
1.000000 63223.000000
2.000000 128690.000000
Calculate Linear Regression计算线性回归
A = [N, sum(x); sum(x), sum(x.*x)];
b = [sum(y); sum(x.*y)];
phi = inv(A)*b;
Is there any way to solve this?有没有办法解决这个问题?
When the x-axis values are not specified then 1:numel(y)
are considered to be the x-axis values.如果未指定 x 轴值,则
1:numel(y)
被视为 x 轴值。
In your code:在您的代码中:
%Your first graph:
plot(x, y, '.b;data;', [0.05 2], phi(1)+phi(2)*[0.05 2], '--r;fit;', [0.05 2]);
%^^^^^^^
%Your second graph:
plot(x, y, '.b;data;', [0.05 2]);
%^^^^^^^^^
plot(phi(1)+phi(2)*[0.05 2], '--r;fit;', [0.05 2]);
%!!!!!!!!!!!!!!!!!!!!!! %^^^^^^^^^
The parts highlighted with ^
in above plot
commands have x=[1 2]
and y=[0.05 2]
and the part highlighted with !
上面
plot
命令中用^
突出显示的部分具有x=[1 2]
和y=[0.05 2]
以及用!
突出显示的部分has x=[1 2]
and y=phi(1)+phi(2)*[0.05 2]
.有
x=[1 2]
和y=phi(1)+phi(2)*[0.05 2]
。 You can see those lines being drawn if you zoom at that area.如果您放大该区域,您可以看到这些线条正在绘制。
So your first plot command should be:所以你的第一个 plot 命令应该是:
plot(x, y, '.b;data;', [0.05 2], phi(1)+phi(2)*[0.05 2], '--r;fit;');
and it should be split like this:它应该像这样拆分:
plot(x, y, '.b;data;');
hold on;
plot([0.05 2], phi(1)+phi(2)*[0.05 2], '--r;fit;');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.