I would like to create a binary 3D matrix (60x96x10), where there are 60*96 ones finally, and their position is randomized and unique. Everytime a 1 occurs, i would like 2 more ones to come after it, but my code is glitching and gives 4 or 5 ones everytime I run it. What is wrong with my code?
function cubefinal = sensingmatrix3d(time) exposure=zeros(60,96,10); if time==3 for j=1:size(exposure,1); for jj=1:size(exposure,2); randnum=randi([1 8]); exposure(j,jj,randnum:randnum+2)=1; end end endend
Best Answer