concatenation - Matlab: how can I create one grid by joining two gridded rectangles of different size (or two matrices with different dimensions)? -


i have spent weekend trying in matlab seems should simple. not experienced matlab user. want calculate flow through tank. requires me define rectangular geometry (the tank), divide cells/elements (a grid made of x/y coordinates). can no problem:

lx = 300;               % geometry length in x direction ly = 150;               % geometry length in y direction  nx = 10; ny = nx;       % number of nodes in x , y direction % grid x = linspace(0,lx,nx); y = linspace(0,ly,ny); delta_x = lx/(nx-1); delta_y = ly/(ny-1);  

here's problem. want add inlet/pipe tank--a second rectangle joined first. diagram of wantno matter do, there "holes" in geometry there no points. also, there never grid points along y=0, problem.

i have tried (1) (below), results in weird-looking check-mark shaped grid:

c = [0 150 150 0  ]; % x dimension of large tank   d = [0 0   150 150]; % y dimension of large tank   v = [0   20  0   20 ]; % x dimension of inlet    w = [150 200 200 0];   % y dimension of inlet   x = union(c(1,:), v(1,:)); y = union(d(1,:), w(1,:)); grid_val = 10;  figure('color','w');   [x,y] = meshgrid(min(x):grid_val:max(x), min(y):grid_val:max(y)); 

i tried (2) making 2 arrays: 1 of x coordinates , 1 of y coordinates. neither method works. finally, have tried (3) concatenating grids after making them , gives me errors grids of different size, can't concatenated. advice welcome.

i think need take different approach here. create meshgrid() such x , y values contain parts of tank , intake. last line seems fine.

next you'll have create additional masking matrix size of x (or y) track whether each coordinate point part of tank or not.

tankmask = zeros(size(x)); 

now loop on elements of x , y , set corresponding value of tankmask 1 if it's part of tank , leave set 0 otherwise.

you should able use matlab's inpolygon() accomplish this:

for = 1:numel(x)     if inpolygon(x(i),y(i),c,d) || inpolygon(x(i),y(i),v,w)         tankmask(i) = 1;     end end 

now, still have grid points, have mask telling whether or not each x,y value part of tank. verify surf(x,y,tankmask).

also i'm not sure want intake like, looks closer may going for:

v = [0   0  20   20]; % x dimension of inlet    w = [150 200 200 150];   % y dimension of inlet  

here i've plotted surf(x,y, tankmask) mask created described , suggested modified v , w vectors.

enter image description here

this method not particularly efficient , run problems grid size gets smaller. it's quick , dirty approach. if need fine grid, want more refined method.

edit: know looks points along y = 160 included in tank (as intake @ x = 30) that's artifact of grid size (10 unit spacing) , how 3d plot visualized.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

utf 8 - split utf-8 string into bytes in python -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -