matlab - How do I obtain the count of corner points in a matrix as well as store their positions in an array? -


i told coordinates of matrix must not represented using centre points, represented using corner points. can’t figure out how go this. nonetheless, have information relates matrix notations both centre , corner points shown below.

enter image description here

[nr, nc] = size(img); 

and:

nr = ny+1; % total no. of centre rows nc = nx+1; % total no. of center columns

also,

ny = nr – 1; % total no. of line rows nx = nc – 1; % total no. of line columns

t = ny * nx; % t = total no. of internal nodes nodecount = nx(iy – 1) + jx;

the count order row-by-row i.e. beginning nodes: (1,1) (1,nx) , (2,1) (2, nx), etc. note in given image (6x6 matrix), nodecount has 25 array elements.

now, need obtain nodecount such contains array of counted internal nodes 1 t in count order specified. obtain x , y coordinates each index in nodecount.

please, need help/suggestions/advice on how resolve this. many thanks.

since discussion in comments got little long, decided answer:

1) create coords (from scratch)

[x,y] = meshgrid(1:nx,1:ny);  coords = [x(:),y(:)]; 

2) create nodecount (from scratch)

nodecount = reshape(reshape((1:nx*ny),nx,ny)',nx*ny,[]); 

3) convert coords nodecount

nodecount = nx*(coords(:,2)-1) + coords(:,1); 

4) convert nodecount coords

coords_x = mod(nodecount-1,nx) + 1; coords_y = (nodecount - coords_x)/nx + 1; coords = [coords_x, coords_y]; 

edit: of course, 3-d works well. depends on how count nodes then. 1 way (untested guess idea):

[x,y,z] = meshgrid(1:nx,1:ny,1:nz); coords = [x(:),y(:),z(:)]; nodecount = ny*nx*(coords(:,3)-1) + nx*(coords(:,2)-1) + coords(:,1) coords_x = mod(nodecount-1,nx) + 1; coords_y = mod((nodecount - coords_x)/nx, ny) + 1; coords_z = (nodecount - coords_x - nx*(coords_y-1))/nx/ny + 1; 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -