Add cells into a square

2 ビュー (過去 30 日間)
Lama Hamadeh
Lama Hamadeh 2022 年 6 月 9 日
編集済み: Matt J 2022 年 6 月 9 日
Hi,
I have the below square. How can I create a mesh of cells inside the square generated from equal subdivision on each edge?
This is how I plotted the square:
ex = [0 1 1 0];
ey = [0 0 1 1];
%visualise the polygon
pgon = polyshape(ex,ey);
figure;
plot(pgon,'EdgeColor','black','FaceColor','none','LineWidth',2)
xlabel('$x$','Interpreter','latex')
ylabel('$y$','Interpreter','latex')
set(gca,'TickLabelInterpreter','latex')
set(gca,'FontSize',12)
Thanks.

採用された回答

KSSV
KSSV 2022 年 6 月 9 日
編集済み: KSSV 2022 年 6 月 9 日
ex = [0 1 1 0];
ey = [0 0 1 1];
m = 5 ;
n = 5 ;
A = [min(ex) min(ey)] ;
B = [max(ex) max(ey)] ;
x = linspace(A(1),B(1),m) ;
y = linspace(A(2),B(2),n) ;
[X,Y] = meshgrid(x,y) ;
plot(X,Y,'k',X',Y','k') ;

その他の回答 (1 件)

Matt J
Matt J 2022 年 6 月 9 日
編集済み: Matt J 2022 年 6 月 9 日
ex = [0 1 1 0];
ey = [0 0 1 1];
pgon = scale(polyshape(ex,ey),1/4); %prototype
[I,J]=ndgrid((0:3)/4);
pgon=arrayfun(@(x,y)translate(pgon,x,y),I,J); %shifted copies
figure;
plot(pgon,'EdgeColor','black','FaceColor','none','LineWidth',2)
xlabel('$x$','Interpreter','latex')
ylabel('$y$','Interpreter','latex')
set(gca,'TickLabelInterpreter','latex')
set(gca,'FontSize',12)
axis equal

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by