How to make MATLAB ignore indices that are out of bounds for a matrix
Show older comments
I am working on a problem that involves the matrix A of size m,n.
if an element of A changes value, i want to make the elements next to it (left, top, right, and below) change value too if they have a certain value of their own.
when i now try to check the elements next to for example A(2,1), it will give me an error message because there exists no element A(2,0),
currently i can only think of a solution that uses many individual if statements for the outer regions of the matrix. which looks something like this:
if mi == 1
if ni == 1 %the element in the upper left corner
if A(1,1) == 2
if A(1,2) == value %the element to the right of the upper left corner
%change value of A(1,2)
if A(2,1) == value
%change value of A(2,1) %the element below the upper left corner
and so on for all the elements that face the outside of the matrix...
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!