RF: refactor matlab writing to predict sizes