I can't use xlswrite because i have a mac so can anyone give a example of how to use dlmwrite if i have a column of text?
Best Answer
On systems that are not running MS Windows, and on MS Windows systems that do not have Excel installed, xlswrite() is restricted to "basic" mode, which can only handle numeric arrays.
To use dlmwrite() to write text, you have to do as Iwrote before:
by submitting an array of pure characters and using a character format in the Precision parameter and setting the delimiter to be empty.
The above includes quoting the words and putting in the comma delimiter between the words and the numbers.
But if you are going to go through all this trouble to prepare everything as character ahead of time, all you have gained is incomprehensibility and slowness of your code, and all you have removed is one explicit file open and close. Better, likely, to use the low-level I/O operationsrecommended in the user guide
fid = fopen(YourFileName, 'wt');
for K = 1 : size(G,1)
fprintf(fid, '"%s",%f\n', F(K,:), G(K));
end
fclose(fid)
That is 5 easy lines that nearly any programmer will understand, compared to 3 lines for the dlmwrite() that relatively few people will understand (and those who do understand them will wonder why you didn't just use fprintf() !)
Going the dlmwrite() route ispossible, but will cause more confusion than it solves problems. The only reason I had for inventing the technique a few years back was that other people said that it couldn't be done.
Best Answer