MATLAB: How to set a colorbar for single values corresponding to multiple polygons created with geoshape

colorbarcolormapgeoshapepatchpolygon

I am trying to create a map similar to the one below, except each polygon needs to be colored corresponding to a single value.
So far, I have created the polygons and included sample values in the structures. Is there a way to create a colorbar for each polygon facecolor corresponding to each 'sampleNum'?
Sample code:
latZone1 = [25, 25, 50, 50, 25];
lonZone1 = [-105, -125, -125, -105, -105];
zone1Poly = geoshape(latZone1, lonZone1, 'sampleNum', 89);
zone1Poly.Geometry = 'polygon';
latZone2 = [25, 25, 40, 40, 25];
lonZone2 = [-100, -105, -105, -100, -100];
zone2Poly = geoshape(latZone2, lonZone2, 'sampleNum', 63);
zone2Poly.Geometry = 'polygon';
latZone3 = [40, 40, 50, 50, 40];
lonZone3 = [-100, -105, -105, -100, -100];
zone3Poly = geoshape(latZone3, lonZone3, 'sampleNum', 45);
zone3Poly.Geometry = 'polygon';
latZone4 = [25, 25, 35, 35, 25];
lonZone4 = [-95, -100, -100, -95, -95];
zone4Poly = geoshape(latZone4, lonZone4, 'sampleNum', 78);
zone4Poly.Geometry = 'polygon';
latZone5 = [35, 35, 40, 40, 35];
lonZone5 = [-95, -100, -100, -95, -95];
zone5Poly = geoshape(latZone5, lonZone5, 'sampleNum', 70);
zone5Poly.Geometry = 'polygon';
latZone6 = [40, 40, 50, 50, 40];
lonZone6 = [-95, -100, -100, -95, -95];
zone6Poly = geoshape(latZone6, lonZone6, 'sampleNum', 25);
zone6Poly.Geometry = 'polygon';
states = geoshape(shaperead('usastatehi', 'UseGeoCoords', true));
figure('Visible','on');
hold on
ax = usamap([25 50],[-125 -65]);
geoshow(states,'FaceColor', 'w')
geoshow(zone2Poly, 'LineWidth', 1,'FaceColor','k')
geoshow(zone1Poly, 'LineWidth', 1,'FaceColor','r')
geoshow(zone3Poly, 'LineWidth', 1,'FaceColor','b')
geoshow(zone4Poly, 'LineWidth', 1,'FaceColor','b')
geoshow(zone5Poly, 'LineWidth', 1,'FaceColor','r')
geoshow(zone6Poly, 'LineWidth', 1,'FaceColor','g')
Any help is greatly appreciated!

Best Answer

Do you mean you want every polygon to be a different colour? And is it then impossible for two polygons to have the same sample number? Or if they do should they be the same colour?
Simplest way would seem to be just to create the colourmap you want as e.g.
cmap = [0 0 1; 0 1 0; 1 0 0; 1 1 0; 0 1 1; 0.5 0.75 0.25];
with as many colours as you have polygons and then just put your samples into an array too as e.g.
sampleNos = [89, 63, 45, 78, 70, 25];
then when you need the colour of a given polygon based on your sampleNum you can just do for example
colour = cmap( find( sampleNos == 78 ), : );
and pass this colour as the 'FaceColor' for that polygon.
As an aside, don't name a load of variables as latZone1, latZone2, latZone3 etc, it is not extendable and leads to really long and messy code. Use arrays instead, then you only need to write a piece of code once and you can apply it to all elements of your array.