Is there any way I can replace this for loop with a vectorized approach?
v = zeros(4, 3);ii = [1 ; 2 ; 3 ; 1 ; 3 ; 4];res = [-1 -1 1 ; -1 -1 1 ; -1 -1 1 ; 1 1 -1 ; 1 1 -1 ; -1 1 -1];for i = 1:3 v(:,i) = accumarray(ii , res(:,i));end
I know if res was just scalar values, I could use this:
v= accumarray(ii , res);
But is it posible to remove the loop knowing that res has more than one columns?
Best Answer