Hi,
I am trying to divide up a meshgrid of zeros in to equal sized boxes, then turn the values of a particular box to equal 1. The idea behind this is to make a mask which can be place on top of another meshgrid so that boxes with zero values are 'not visible' and boxes with ones are 'visible'. The goal it to keep some central box 'on' and cycle through all the other boxes, turning them on and then off again individually. I have written some code which makes the mesh of zeros, 680 by 600 and then divides the mesh in to 68 by 60 boxes and can set the value of each box equal to 1, see below.
The issue I am having is that I cannot figure out a way of:
- Firstly: adding the 1 values of a particular box back to the meshgrid i.e. box 2×3 corresponds to the mesh coordinates (21,31) to (30,40). So the Mesh would be all zeros apart from the cells the square outline by those coordinates.
- Secondly: A way to set up the code with the features described in above but so that I could select the box I wanted to turn on at will, so for example – turn on the values in box 2×3- do something interesting- turn 2×3 back off- turn 3×3 on- ect…
Thank you for any help you can provide. I feel like I am close but just can pull the last bit together.
clear all; clc x = 680; y = 600; Mesh = zeros(x , y); [X,Y] = size(Mesh); L = 10; ki = 0; kj = 0; for i = 1 : L : X ki = ki + 1; for j = 1 : L : Y; kj = kj + 1; SubMesh = Mesh(i : (i + L - 1), j : (j + L - 1)); SomeOnes = ones( size(SubMesh) ); SomeOnesMesh = SubMesh * SomeOnes; end end kii = ki kjj = kj / kii
Best Answer