I have one matrix like below-
A=[1 1 1 1 1; 0 1 1 1 2; 0 0 1 1 3]
But I want to place all the 0 at the end of the row, s
0
Try this (just a fast hack):
for row_k = 1:size(A, 1) [A_sorted, A_sortmap] = sort(A(row_k, :) == 0, 'ascend'); % update row in A: A(row_k, :) = A(row_k, A_sortmap); end
Now optimized for versions of MATLAB not supporting ~ as garbage lhs-identifier.
~