MATLAB: How to rotate rows of a matrix

indexingrotate

I have a matrix A where each row of A has only one value of 1 and the rest are some other number.
A = [9 8 7 1; 9 1 8 7; 9 8 1 7; 9 1 8 7; 9 8 7 1; 1 9 8 7]
How can I rotate all of the rows individually such that the 1 value is in the first column of each row in the resultant matrix? How about the second column? I'd like to do this without a for-loop because I am working with large matrices.
%%% Result:
% First column.
B = [1 9 8 7; 1 8 7 9; 1 7 9 8; 1 8 7 9; 1 9 8 7; 1 9 8 7];
% Second column.
C = [7 1 9 8; 9 1 8 7; 8 1 7 9; 9 1 8 7; 7 1 9 8; 7 1 9 8];

Best Answer

I think a for-loop is your best bet:
for k = 1:size(A,1)
f = find(A(k,:)==1,1);
A(k,:) = circshift(A(k,:),1-f);
end