首页 文章

Matlab - 绘制特定点中两个图之间的差异

提问于
浏览
-3

我有两个图,一个是解的精确图,另一个是数值方法 . 我的图中有4个特定点(t = 0.25,0.5,0.75,1),我想用直线说明两个图之间的差异 . 我找到了错误栏功能,但我没有看到任何用途 . 希望你能帮我!

编辑:

这是示例图:

t = [0:0.25:1]; 
y = t.*4; 
x = t.^2+3; 
plot(t,y,t,x)

我现在有4分,t = 0.25; T = 0.5; T = 0.75; T = 1;在这一点上,我只想要两个图之间的垂直线 . 我已经尝试过这个: plot([t(1),y(1)],[t(1),x(1)])

但它只是在整个人物上创造了一条线 .

1 回答

  • 0

    在第二次使用plot命令之前,您似乎没有使用hold on,因为否则您将获得所需的结果(实际上这不是绘制垂直线的正确方法) .

    您正在为 plot(x,y) 混合 xy 的值 . 要绘制垂直线,应该像这样使用: plot([x,x], [y1,y2])
    对于您的情况,您可能没有注意到 plot([t(1),y(1)],[t(1),x(1)]) (这是不正确的)和 plot([t(1),t(1)],[x(1),y(1)]) (这是正确的)之间的区别,因为它们是偶然的值相同 . 将其绘制为其他一些点,您将意识到其中的差异 .

    Fixed Code:

    t = [0:0.25:1]; 
    y = t.*4; 
    x = t.^2+3; 
    plot(t,y,t,x) 
    hold on
    plot([t(1) t(1)],[x(1) y(1)])  
    % You have 't' on your horizontal axis and 'x'and 'y' values on the vertical axis
    axis equal     % just for better visualization
    

    Output:

    output

相关问题