Generate coordinates for plotting a hexagonal mesh with the nsidedpoly function
Afficher commentaires plus anciens
Hi, I am trying to plot a hexagonal mesh using the nsidedpoly function as shown in the following code. I am taking the coordinates (coord array) from a file but I want to generate them myself in the code. How can I do this, by rings and counterclockwise, as shown in the figure?
Thank in advance.
radius = 5.6617/(sqrt(3)/2);
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, :), 'Radius', radius);
end
pg = plot(poly);
axis off
axis equal
% Convert num2str
POS = num2str(POSITIONS);
% Convert str2double
for i = 1:length(POSITIONS)
c = POS(i, :);
p(i, :) = str2double(c(~isspace(c)));
end
a = 0.5;
b = 1.5;
r = (b-a).*rand(87, 1) + a;
r = [p [1:87]'];
power = repmat([], 87, 1);
power(1:6, :) = r(ib(1:6), :);
power(7:13, :) = r(ib(7:13), :);
power(14:21, :) = r(ib(14:21), :);
power(22:29, :) = r(ib(22:29), :);
power(30:39, :) = r(ib(30:39), :);
power(40:48, :) = r(ib(40:48), :);
power(49:58, :) = r(ib(49:58), :);
power(59:66, :) = r(ib(59:66), :);
power(67:74, :) = r(ib(67:74), :);
power(75:81, :) = r(ib(75:81), :);
power(82:87, :) = r(ib(82:87), :);
nLevel = 256;
cmap = colormap(jet(nLevel));
polyFaceColor = cmap(ceil((power(:, 2)-a)*nLevel/100), :);
for i = 1:length(pg)
pg(i).FaceColor = polyFaceColor(i, :);
pg(i).FaceAlpha = 0.5;
end
str = num2str(power(:, 2), 4);
t2 = text(coord(:, 1), coord(:, 2), str,'HorizontalAlignment', 'center','VerticalAlignment','middle', 'FontSize', 10, 'FontName', 'Times');

Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

