Search code examples
csvoctave

Append Delimiter to Rows using Octave's dlmwrite function


A toy example of problem: repeatedly using Octave's "dlmwrite" function thus

dlmwrite('file',[1 2],'-append',0,8);

will give

,,,,,,,,1,2
,,,,,,,,1,2
,,,,,,,,1,2

but what I really want is this

1,2,,,,,,,,,
1,2,,,,,,,,,
1,2,,,,,,,,,

How can I use the "dlmwrite" function to append the delimiter to rows, rather than prepend, to give the result I want?


Solution

  • You could use the newline option of dlmwrite to add commas before newline.

    comma = repmat(',', 1, 8); % creates ",,,,,,,,"
    dlmwrite('file', [1 2], '-append', 'newline', [comma '\n']);
    

    You can change \n to \r\n or \r if you are on Windows or Mac.