MATLAB: Reshape non-even length columns into text output

dlmwritegridgridded datamodflowoutputreshaperestructure

Hi All-
I'm trying to convert some data from one form to another, and have run into trouble. I have a large matrix of data (257 x 257). For each row, I need to write space-separated output so that the first 10 values are on one line, the next 10 on another, etc. This would be fairly easy to do using reshape, except when I get to the last line there are only 7 values remaining, so matlab returns an error.
For example, if I had:
data = [1:13; 14:26];
I would want my output from dlmwrite to be:
1 2 3 4 5 6 7 8 9 10
11 12 13
14 15 16 17 18 19 20 21 22 23
24 25 26
Any advice? I'm using R2011a. Thanks in advance! -sam

Best Answer

You can do custom stuff like that easily with fprintf().