let matrix_next_coordinates mat table prev_row prev_col =
let row = ref prev_row in
let col = ref prev_col in
let next_coord () =
if !col = table.col_nb - 1 then
(col := 0; incr row;) else (incr col;) in
next_coord ();
while mat.(!row).(!col) <> `none do
next_coord ();
done;
(!row, !col)