- #1
Beer-monster
- 296
- 0
*apologies for spelling error in title*
Hi
I'm writing a code that first reads a random element of an NxN matrix and then reads out the nearest neighbouring elements. However, if the first element chosen at the edge of the matrix the code then tries to read an element that is not there and flags and error.
I'd like to introduce a wrap-around so that if the code reads of the edge of a row/column is reads the first element in that row column.
i.e if the code chooses the element 5,N and tries to read the element 5,N+1 it will return the value in the element 5,1.
I thought I could accomplish this by adding the mod command in my matrix reference, but it doesn't seem to be working. Could someone please tell me what I'm doing wrong.
The relevant part of the code is shown below. The code has already chosen the element in (B(1), B(1)) in matrix A (B is a reference vector).
c=mod(B(1)+1,N)
s1=L1(c,B(2))
S1=L2(c,B(2))
Thanks
Hi
I'm writing a code that first reads a random element of an NxN matrix and then reads out the nearest neighbouring elements. However, if the first element chosen at the edge of the matrix the code then tries to read an element that is not there and flags and error.
I'd like to introduce a wrap-around so that if the code reads of the edge of a row/column is reads the first element in that row column.
i.e if the code chooses the element 5,N and tries to read the element 5,N+1 it will return the value in the element 5,1.
I thought I could accomplish this by adding the mod command in my matrix reference, but it doesn't seem to be working. Could someone please tell me what I'm doing wrong.
The relevant part of the code is shown below. The code has already chosen the element in (B(1), B(1)) in matrix A (B is a reference vector).
c=mod(B(1)+1,N)
s1=L1(c,B(2))
S1=L2(c,B(2))
Thanks