MATLAB: How to specify line colors for 2D plots created using arrays

2dcoordinates given as arrayscustom colorsplot

This is the code I'm using to create shapes by plotting lines that overlap each other:
x = [10 16 10 10];
y = [12 10 8 12];
figure(1)
plot (x,y)
axis([0 100 0 100])
The issue I'm having is how to specify the line color for each line segment plotted or for the all the lines creating the shape. How do I specify the line color when each line is plotted using coordinates within arrays? I have a for-loop that creates a large amount of these shapes as a function.

Best Answer

This is not possible in MATLAB using plot() or related calls. plot() and related calls use line() objects, and line() objects are restricted to a single color.
You can break the vector into segments and draw the segments separately.
If you look in the File Exchange you will find a couple of different contributions for drawing colored lines.