This is how I would do it.
%this returns the indeces of all nonzero elements of A to elements of X.
X=find(A)
%this makes a new matrix (column vector) that is as long as X but with the elements in A, which have indeces given by the elements of X
B(1:size(X))=A(X)
%Just make a function that imports the variable, runs it through this program, and then spits it into the workspace or a .mat file or whatever.
Custodes