Presenting entries in the format of three columns, as well as a list of coordinates (i, j, value), you can simply select elements from the list. To get this, you can either use your original method to create a sparse matrix (that is, the sparse() predecessor), or use the find , a la [i,j,s] = find(S);
If you don't need records, and it seems you won't, you can simply extract i and j .
If for some reason your matrix is massive and the RAM restrictions are severe, you can simply divide the matrix into regions and allow the probability of choosing this submatrix to be proportional to the number of nonzero elements (using nnz ) in this submatrix. You can go so far as to divide the matrix into separate columns, and the rest of the calculation is trivial. NB: by applying sum to the matrix, you can get the number of columns (assuming your records are 1 s).
This way, you don’t even have to worry about selective sampling (this seems senseless to me in this case, since Matlab knows where all the non-zero entries are).
source share