I'm intending on altering the values of a matrix (A) based on values in a another (B) in order to completely fill out the original matrix. Here's what I mean:
A= 0 0 0 1 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 1 B= 0 0 0 2 0 0 2 0 3 0 4 0 0 0 1 0 0 0 0 4 2 0 0 3 4
based on the value that appears at the corresponding location in matrix B determines which other location a point in A will populate. In other words if B(1,4)=2 then the A(1,4)=1 and A(1,5)=1. However this requires that A(1,5)=0 before being replaced with a 1.
if B(x,y)==1 && A(x,y-1)==0 A(x,y)=1 A(x,y-1)=1 elseif B(x,y)==2 && A(x,y+1)==0 A(x,y)=1 A(x,y+1)=1 elseif B(x,y)==3 && A(x+1,y)==0 A(x,y)=1 A(x+1,y)=1 elseif B(x,y)==4 && A(x-1,y)==0 A(x,y)=1 A(x-1,y)=1 end
this is the code I currently have however whenever I run it it only replaces values in the y+1 direction and none of the others. Am I writing this correctly? Is their a better way to write this? Any help would be greatly appreciated thank you!
Best Answer