필터 지우기
필터 지우기

how can i plot the line in different colours

조회 수: 2 (최근 30일)
Hannes Arnar
Hannes Arnar 2015년 9월 14일
답변: Image Analyst 2015년 9월 14일
close all; clear all; clc;
x = -5:0.01:5;
y = zeros(1,length(x));
for i = 1:length(x)
if(x(i) < -1)
y(i) = x(i) + 2;
hold on
elseif(x(i) <= 2 )
y(i) = x(i)^2;
hold on
elseif(x(i) > 2)
y(i) = -2*x(i) + 8;
hold on
end
end
plot(x,y)
  댓글 수: 1
Hannes Arnar
Hannes Arnar 2015년 9월 14일
How can i make the line bigger ?
close all; clear all; clc;
x = -5:0.01:5; y = zeros(1,length(x));
cond1 = x < -1; cond2 = x >= -1 & x <= 2; cond3 = x > 2; y( cond1 ) = x( cond1 ) + 2; y( cond2 ) = x( cond2 ).^2; y( cond3 ) = -2 * x( cond3 ) + 8; figure; plot( x( cond1 ), y( cond1 ), 'r:' ) hold on plot( x( cond2 ), y( cond2 ), 'b:' ) plot( x( cond3 ), y( cond3 ), 'g:' )

댓글을 달려면 로그인하십시오.

채택된 답변

Adam
Adam 2015년 9월 14일
Just plot three different lines and give them each a colour rather than plotting them in a single instruction. You can also put the numbers into the vector without requiring a for loop too e.g.
cond1 = x < -1;
cond2 = x >= -1 & x <= 2;
cond3 = x > 2;
y( cond1 ) = x( cond1 ) + 2;
y( cond2 ) = x( cond2 ).^2;
y( cond3 ) = -2 * x( cond3 ) + 8;
figure;
plot( x( cond1 ), y( cond1 ), 'r' )
hold on
plot( x( cond2 ), y( cond2 ), 'g' )
plot( x( cond3 ), y( cond3 ), 'b' )

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 9월 14일
Regarding your question about line width in your comment above, to make the line bigger (thicker), change the 'LineWidth' option:
plot(x(cond3), y(cond3), 'g:', 'LineWidth', 3);

카테고리

Help CenterFile Exchange에서 Filter Banks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by