MATLAB: How to create a multiple fill with different colors using loops for an arbitrary vector

fill with vectorfor loop for multiple fillmultiple fill

Hi all, I am not very advance in matlab so forgive me if I mix up the terms. I understand the basics of how to use the fill function fill(X,Y,C). From matlab documentation, it can also be used for multiple fills say fill(X1,Y1,C1,X2,Y2,C2,…).
I have a vector
X = [1 2 2 2 4 4 5 5 3 3 3 1 1 1]
and
Y = [0 1 1 0 0]
Nz = linspace(0,1,length(X))
dz = max(Nz)/length(X)
I want to write a for loop to create a multiple fill for each identical successive element with different colors for example
x1 = [0 dz*count dz*count 0 0]
Y = [0 1 1 0 0]
x2 = [dz*count dz*count2 dz*count2 dz*count dz*count]...
Y = [0 1 1 0 0]
C1,C2...
fill(x1,Y,C1,x2,Y,C2...).
"count" here determines the number of times successive elements occur in the vector. "dz" is the step size. I would be glad if anyone here can assist. Thank you.

Best Answer

Hello, Guillaume, I want to thank you so much for your assistance throughtout this thread. It has been really invaluable. Also thank you Stephen Cobeldick. With regards to the last question, with some experimentation, I was able to use a for loop to loop through like so
fill(xpoints(:,ii), ypoints(:,ii),colormap(colour(ii,:)))
and got what I was looking for. Thank you very much.