필터 지우기
필터 지우기

plot different x ranges

조회 수: 3 (최근 30일)
masih
masih 2017년 6월 9일
편집: the cyclist 2017년 6월 9일
Hi All,
I have some big data in which x values must be broken into pieces and each piece with its corresponding y values must be plotted with a different color on the same plot? for example, if 5<x<9, then graph must be plotted in blue for example, and if 10<x<15, then graph must be plotted in red. How should I do this? Thanks.

답변 (1개)

the cyclist
the cyclist 2017년 6월 9일
편집: the cyclist 2017년 6월 9일

Here is one way:

% Some made-up data
x = 1:0.25:10;
y = x + 0.5*rand(size(x));
% Identify the x ranges
redIndex  = x <  5;
blueIndex = x >= 5;
% Plot
figure
hold on
h = plot(x(redIndex),y(redIndex),  'r.', x(blueIndex),y(blueIndex),'b.');
set(h,'MarkerSize',24) % Don't really need this, but wanted the markers to really show

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by