How to avoid nested for loops in matlab?
问题 I am constructing an adjacency list based on intensity difference of the pixels in an image. The code snippet in Matlab is as follows: m=1; len = size(cur_label, 1); for j=1:len for k=1:len if(k~=j) % avoiding diagonal elements intensity_diff = abs(indx_intensity(j)-indx_intensity(k)); %intensity defference of two pixels. if intensity_diff<=10 % difference thresholded by 10 adj_list(m, 1) = j; % storing the vertices of the edge adj_list(m, 2) = k; m = m+1; end end end end y = sparse(adj_list(