how can i plot the line in different colours
Show older comments
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 Comment
Hannes Arnar
on 14 Sep 2015
Accepted Answer
More Answers (1)
Image Analyst
on 14 Sep 2015
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);
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!