*apologies for spelling error in title*(adsbygoogle = window.adsbygoogle || []).push({});

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

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab help plese: Modulo wrap around.

Loading...

Similar Threads - Matlab help plese | Date |
---|---|

Matlab MATLab: Not enough inputs for nlinfit | Nov 16, 2017 |

Matlab Help needed to fix a matlab code | Nov 8, 2017 |

New to Matlab, help with vectors | Feb 20, 2016 |

Need help with integral | Dec 23, 2015 |

Communication between Arduino and Matlab Help | Jun 19, 2015 |

**Physics Forums - The Fusion of Science and Community**