Assign a colormap to an array to plot with the nsidepoly function.
Show older comments
Hi, this code plots a hexagonal mesh using the nsidedpoly function, where each hexagon is labeled with the corresponding r-value. The problem is that each hexagon is plotted independently and I can't apply any colormap only the red color (FaceColor.) How can I assign the values of a colormap (for example jet()) to the r-values depending on their value?
Thanks in advance.
x = load('COORDXY');
coord = [x(230:235, :)
x(256:262, :)
x(282:289, :)
x([308:310,312:316], :)
x(334:343, :)
x([360:364,366,368:370], :)
x(387:396, :)
x([414:416,418:422], :)
x(441:448, :)
x(468:474, :)
x(495:500, :)];
for i = 1:length(coord)
poly(i) = nsidedpoly(6, 'Center', coord(i, :), 'SideLength', 5.6617);
end
pg = plot(poly);
axis off
axis equal
a = 0.5;
b = 1.5;
r = (b-a).*rand(87, 1) + a;
cmap = jet(15);
colormap(jet(10));
for i = 1:length(pg)
pg(i).FaceColor = 'r';
end
colormap(jet(10));
cmap = jet(87);
str = num2str(r, 2);
t2 = text(coord(:, 1), coord(:, 2), str, ...
'HorizontalAlignment', 'center','VerticalAlignment','middle', 'FontSize', 10, 'FontName', 'Times');

Accepted Answer
More Answers (0)
Categories
Find more on Color and Styling 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!