displaying specific range of data with different color in a plot

11 ビュー (過去 30 日間)
Mayowa
Mayowa 2014 年 11 月 26 日
コメント済み: SAIF MEHDI 2020 年 5 月 5 日
I have a data say x and y vectors. I want to plot x and y, however I want certain part to have different color from the others. How can I get it done.

回答 (2 件)

Thorsten
Thorsten 2014 年 11 月 26 日
I know of no other way as splitting the x into those different parts that you need to color differently. E.g., to plot negative values in red and positive values in blue:
x = -10:0.1:10;
plot(x(x<=0), sin(x(x<=0)), 'r', x(x>=0), sin(x(x>=0)), 'b')

ben hirsig
ben hirsig 2018 年 3 月 21 日
編集済み: ben hirsig 2018 年 3 月 21 日
Here's my solution. Disregard the 'if true' 'end' statements. I'm not sure how to get rid of them without changing the rest to just simple text and not code.
if true
figure()
hold on
scatter(t(1:278), predicted(1:278), 'or'); % Plot red circles for elements 1:278
scatter(t(279:end), predicted(279:end), 'ob'); % Plot blue circles for the remaining elements
end
  1 件のコメント
SAIF MEHDI
SAIF MEHDI 2020 年 5 月 5 日
Hi,
I tried your method but it drew another line instead of completing the rest of the plot
plot(BAPred(1:300))
hold on
plot(BAPred(300:end))

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

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by