I have a script (shown below) that will generate a 12×12 matrix of all 0's and a single 1, which will replicate in a randomised order 7200 times. There are three features I want to add to this script but don't know how:
- Instead of generating a matrix in a complete random order I want digits to move either one place up, down, left or right from their position in the previous matrix.
- A shortcut that will create an imagesc() for all 7200 matrix's (like the image below).
Any help would be greatly appreciated.
Thanks,
Joe
count=0;m=zeros(144,1);rand_int=datasample(1:144,1);m(rand_int)=1;old_matrix=reshape(m,[12 12]);for i=1:7200 m=zeros(144,1); rand_int=datasample(1:144,1); m(rand_int)=1; new_matrix=reshape(m,[12 12]); if sum(abs(old_matrix-new_matrix),'All')>0 count=count+1; end old_matrix=new_matrixend
Best Answer