I have a sparse matrix in Matlab. I would like to save the positions of 1's in the matrix row-wise and column-wise.
For example consider the below matrix:
0 1 0 1 0
0 0 0 1 0
0 0 0 0 0
0 0 1 0 0
1 0 0 0 0
I would like two files written as: row-wise.csv:
1,2
1,4
2,4
4,3
5,1
column-wise.csv:
5,1
1,2
4,3
1,4
2,4
I know I can run a loop row-wise or column-wise and save element by element using fprintf, but is there a better way? I'm dealing with very large matrices and I'm wondering what an efficient way is to do this?