From: Cat on 19 Jul 2010 09:23 Hello, I've spent the last 6hours trying to sort what i believe is a very basic problem but i just can't get my head around it. I have a lattice A(20,20) where the values of each cell either equal 0 or 1. What i want to do is that if a cell A(m,n) in my lattice is equal to zero, i want to search its neighbours (originally 8 cells or Moore's neighbourhood) for cells that equal one. It's vital that i retain some measure of distance for a future caluclation. If i set the distance to 1 (i.e. one neighbourhood away), i use distance=-1:1 NN_search=A(m+distance, n+distance) which gives me exactly what i want, a mini lattice of the neighbourhood cells However if i want to set the distance value at >1, i cannot figure out how to search for it without including neighbours at distance 1 etc. I figure there is two ways i can approach this problem: 1. Search for each specific neighbourhood distance individually 2. Create full search matrix of all distances i want (e.g. A(m+(-4:4), n+(-4:4)) and somehow index into that matrix for each distance to find answer. I'd really appreciate some help on this and if i have not explained myself very well, please don't hesitate to ask any further questions.
From: Andy on 19 Jul 2010 09:30 It's not clear what you want to be returned. In the distance 1 case, you seem to have returned the distance 1 and distance 0 neighbors (resulting in a 3x3 array). What are you trying to return in the distance 2 case? Specifically, what should the size of the returned array be? Could you produce a small sample adjacency matrix A (say, 6x6) and what you expect your entire output to look like?
From: John D'Errico on 19 Jul 2010 09:35 "Cat " <c.o'connor(a)vet.gla.ac.uk> wrote in message <i21jjo$ar5$1(a)fred.mathworks.com>... > Hello, > > I've spent the last 6hours trying to sort what i believe is a very basic problem but i just can't get my head around it. > > I have a lattice A(20,20) where the values of each cell either equal 0 or 1. > > What i want to do is that if a cell A(m,n) in my lattice is equal to zero, i want to search its neighbours (originally 8 cells or Moore's neighbourhood) for cells that equal one. It's vital that i retain some measure of distance for a future caluclation. > > If i set the distance to 1 (i.e. one neighbourhood away), i use > distance=-1:1 > NN_search=A(m+distance, n+distance) > which gives me exactly what i want, a mini lattice of the neighbourhood cells > > However if i want to set the distance value at >1, i cannot figure out how to search for it without including neighbours at distance 1 etc. > > I figure there is two ways i can approach this problem: > 1. Search for each specific neighbourhood distance individually > 2. Create full search matrix of all distances i want (e.g. A(m+(-4:4), n+(-4:4)) and somehow index into that matrix for each distance to find answer. > > I'd really appreciate some help on this and if i have not explained myself very well, please don't hesitate to ask any further questions. conv can do the computation for any given distance, at least for every cell. Then you merely look at the cells you care about. John
From: Matt J on 19 Jul 2010 09:35 "Cat " <c.o'connor(a)vet.gla.ac.uk> wrote in message <i21jjo$ar5$1(a)fred.mathworks.com>... > If i set the distance to 1 (i.e. one neighbourhood away), i use > distance=-1:1 > NN_search=A(m+distance, n+distance) > which gives me exactly what i want, a mini lattice of the neighbourhood cells > > However if i want to set the distance value at >1, i cannot figure out how to search for it without including neighbours at distance 1 etc. =========== Why not just exclude the values you don't want from the distance vector distance=[-3 -2 2 3]; % distances up to 3 excluding distances <=1
From: Cat on 19 Jul 2010 09:46 "Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i21k1j$8sg$1(a)fred.mathworks.com>... > It's not clear what you want to be returned. In the distance 1 case, you seem to have returned the distance 1 and distance 0 neighbors (resulting in a 3x3 array). What are you trying to return in the distance 2 case? Specifically, what should the size of the returned array be? > > Could you produce a small sample adjacency matrix A (say, 6x6) and what you expect your entire output to look like? Hi Andy, What i really want returned is the value of the cells at each distance, so for the below example where i looked at a distance of 1 from central cell (8 cells), i have 2 cells with a value of 1 and 6 cells with a value of zero. This is of course discounting central cell. B= 0 0 0 0 0 1 1 0 0 Then for this next example, i again what the values of each cell. So at distance 1 from central cell, cells with value of 1=2 and cells with value of zero= 6. At distance 2 (the 16 cells surrounding cells at distance 1), there are 2 cells with value of 1 and 14 with value of zero. B= 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 0 Ideally if i can somehow produce a list of cells at the different distances, e.g. distance_1=[0,0,1,0,0,0,0,1,0] distance_2=[0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0] Thanks C
|
Pages: 1 Prev: approximate hessian after ktrlink Next: Calling S-function builder |