1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| nElmtsOnSide = 40;
squareSize = 4; %cm
seeds = linspace(0, squareSize, nElmtsOnSide+1);
[coordX,coordY] = meshgrid(seeds);
nodes = [coordX(:) coordY(:)];
indices = reshape(1:(nElmtsOnSide+1)*(nElmtsOnSide+1), nElmtsOnSide+1, []);
elmts = zeros(nElmtsOnSide*nElmtsOnSide,4);
for i = 1:nElmtsOnSide
for j = 1:nElmtsOnSide
idx = sub2ind(size(indices), [i i i+1 i+1], [j j+1 j+1 j]);
elmts((i-1)*nElmtsOnSide+j,:) = indices(idx);
end
end
figure
patch('vertices', nodes, 'faces', elmts, 'facecolor', 'g')
hold on
plot(coordX, coordY, 'r*');
axis equal tight |
Partager