Plotting the difference between 2 vectors points in 2D

I have two vectors [x1,x2...xn] and [y1,y2...yn]. y is simply a noisy version of x. After plotting x on a 2D graph with connected points, I would like to plot just the points of y, with a straight line connecting each point of y to the corresponding "true" point in x. Thanks!

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 4 月 22 日

0 投票

Provided that the original x and y are row vectors,
hold on
h = plot([x; y]);
set(h, 'Color', 'k')
The 'k' means black, a color I chose arbitrarily for this purpose. Without that set() call, each of the lines will show up a different color.

2 件のコメント

Matt
Matt 2012 年 4 月 22 日
Walter, thanks for the quick reply. However, I am not sure this is the answer. For example, take the arbitrary x and noisy x (y):
t = [0 1 2 3 4];
x = [1 1 2 2 3];
y = x + 0.2*randn(1,5);
plot(t,x)
%here I would try your answer:
hold on
h = plot([x;y]);
set(h, 'Color', 'k')
For some reason this produces a strange graph.
Walter Roberson
Walter Roberson 2012 年 4 月 22 日
h = plot(t, [x;y])
You need to be consistent on your x axis coordinates.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

タグ

質問済み:

2012 年 4 月 22 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by