MATLAB: How to create a mask array to specify a region which represents a cross sectional area (peculiar shape) and omit square regions from a meshgrid

mask arraymeshgrid

Hi all,
The cross sectional area in question is a 50 by 20 rectangle, with two square regions 'missing', so it resembles an E on its back. Both squares are 10×10.
Thanks in advance.

Best Answer

L = 5*10 ;
B = 20 ;
nx = 100 ;
ny = 100 ;
x = linspace(0,L,nx) ;
y = linspace(0,B,ny) ;
[X,Y] = meshgrid(x,y) ;
%%Get 10X10 grids
idx1 = (X>=10 & X<=20) & (Y>=10 & Y<=20) ;
idx2 = (X>=30 & X<=40) & (Y>=10 & Y<=20) ;
%%plot
plot(X,Y,'.r')
hold on
plot(X(idx1),Y(idx1),'Ob')
plot(X(idx2),Y(idx2),'Ob')