make a 10x10 manhattan grid and add midpoint nodes in matlab

main.m
% Create a 10x10 Manhattan grid
rows = 10;
cols = 10;
G = gridGraph(rows,cols);
plot(G)

% Add midpoint nodes
midpointNodes = [];
for i = 1:rows-1
    for j = 1:cols-1
        midpoint = [i+0.5, j+0.5]; % Calculate midpoint between nodes
        midpointNodes = [midpointNodes; midpoint];
    end
end

hold on
plot(midpointNodes(:,1), midpointNodes(:,2), 'ro', 'MarkerSize', 10)
hold off
388 chars
19 lines

related categories

gistlibby LogSnag