Hello, all. I am currently trying to create a figure in which I am drawing multiple rectangles on a graph, and then trying to shade them to a certain colormap that is related to a tertiary value. I can't really figure out how to do this via examples online, and I would appreciate some assistance.
My question can be simplified: if I have a nx1 array between 0 and some arbitrary max, how would I determine the color of each element assuming I have the jet colormap set from 0 to the same arbitrary max?
Here is the rectangle code that I am working with:
rectanglesWithValue = [1 1 30; 1 2 60; 1 3 20; 2 1 -1; 2 2 0; 2 3 80; 3 1 50; 3 2 40; 3 3 -1]; xMin = 0; xMax = 3; yMin = 0; yMax = 3; numRectanglesInX = 3; numRectanglesInY = 3; rectWidth = (xMax - xMin)/numRectanglesInX; rectHeight = (yMax - yMin)/numRectanglesInY; figure; axis([xMin xMax yMin yMax]) for i1 = 1:length(rectanglesWithValue(:,1)) %%%IF THE THIRD VALUE OF THE RECTANGLE IS EQUAL TO -1, FILL IT IN BLACK
if rectanglesWithValue(i1,3) == -1 colouring = 'black'; else %%%IF THE THIRD VALUE OF A RECTANGLE IS BETWEEN min AND max
%%%OF (rectanglesWithValue(:,3)) SET IT TO THE COOL COLORMAP
elementToLinkToColorMap = rectanglesWithValue(i1,3) %%%This is the code I can't determine
colouring = ??? link elementToLinkToColorMap to the cool color map %%%This is the code I can't determine
end rectangle('Position',[rectanglesWithValue(i1,1)-rectWidth/2 rectanglesWithValue(i1,2)-rectHeight/2 rectWidth rectHeight],'FaceColor',colouring); end
Thanks!
Best Answer