MATLAB: How to write matrix elements to file Are contiguous , including a comma

matrixnotbad

I use this function Are contiguous , x=[1 2;3 4;5 6]
x =
1 2
3 4
5 6
>> dlmwrite('myFile.txt', x)
and this what is written in myFile.txt
1,2
3,4
5,6
I want the result to be
1,2,3,4,5,6
Can I do this and how?

Best Answer

Convert your matrix into a row vector:
dlmwrite('myfile.txt', reshape(x', 1, []))
is one way to do it.