MATLAB: How to write this data into a sparse matrix

datasparse matrix

Dear All,
I have this data which is represent 0,1 matrix. it is given in this way. the first element 12,4,3,18,19,10 means the number of position of the ones in this row. I want to create a sparse matrix for it. can anyone help me with it?
12 1 2 3 4 60 61 62 63 89 90 91 95
4 32 33 34 35
3 83 84 91
18 39 40 41 42 43 71 72 73 74 75 76 77 88 90 92 93 94 95
19 29 30 31 32 33 34 35 36 37 79 80 81 83 84 85 86 87 88 89
10 73 86 87 88 89 90 91 92 93 94
the final matrix should have size 6×95. I appreciate any help.
regards,
Nadia

Best Answer

columns = {[12 1 2 3 4 60 61 62 63 89 90 91 95]
[4 32 33 34 35]
[3 83 84 91]
[18 39 40 41 42 43 71 72 73 74 75 76 77 88 90 92 93 94 95]
[19 29 30 31 32 33 34 35 36 37 79 80 81 83 84 85 86 87 88 89]
[10 73 86 87 88 89 90 91 92 93 94]}
rows = arrayfun(@(row) repmat(row, 1, numel(columns{row})), 1:numel(columns), 'UniformOutput', false);
out = sparse([rows{:}], [columns{:}], 1)