Thank you for this nice piece of code. I had the same problem as George with the \t delimiter and changed it in a similar way, unfortunately before reading his comment ;-)Nevertheless this file saved me a lot of work!
Needed to output a cell to .csv file. However when I used the "cell2csv" command from the file exchange, newline characters were not recognized by notepad when I opened the csv file. The newline characters were recognized by Excel 2010 though.
opening cell2csv_test.csv in notepad:
However this function did output to a .csv file with newline characters recognized by notepad. It's not a huge deal, but I was trying to make a csv file that matched a template at work *exactly* (with newlines recognizable by notepad).
I changed the lines 96 to 104 which were the following:
% Cell i,j is written to the output file. A delimiter is appended
% for all but the last element of each row.
if j ~= size(cell_array,2)
% At the end of a row, a newline is written to the output file.
into the following:
% Cell i,j is written to the output file. A delimiter is appended for
% all but the last element of each row. At the end of a row, a newline
% is written to the output file.
if j < size(cell_array,2)
and it runs fine. The newline written to the output file at the end of each line was erroneously left outside the for j = 1:size(cell_array,2) loop. In addition the delimiter and the '%s' strings were concatenated into a single string to provide input for the fprintf function.
Thanks for the code. I am facing a problem. Basically, I have a huge .mat file containing a list of urls. This i convert to cell format and now each row is a url, and there are around 300k rows. Now when I try to write this huge cell into a text file, it stops after around 4000 lines and says index exceeds error.
This utility doesn't work consistently for me. Specific problems:
1) Documentation states that file name is taken as the file specification. However, the function occasionally generates errors like the following:
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in dlmcell (line 98)
fprintf() requires a file handle as first argument. I'll therefore have to dig into this F/E function & possibly modify.
2) This function doesn't return any values, even on error. Instead, it prints error messages at the command-line & returns normally. This is poor programming practice & makes it inconvenient to deploy within another function where error-detection must be handled programmatically.
Great work, absolutely phenomenal for what I'm trying to do. I have one problem though. In my cell array that's being printed, one of my columns has a comma in it i.e. "contract 5,000 bushels" turns into "contract 5" "000 bushels" Is there a way to fix this?
I encountered the same problem as sohrab, with \t printed in the file rather than tabs. I fixed it by replacing row 100 from
Cool function. But using dlmcell I could only write the first element of my cell.
My cell is in the following format;
[1x5 double] [0.1962] [1x3 double] [2x3 double];
I could only write the first element of each cell content unless I need to type all the contents of my cell using the curly brace format.
Can anyone help me with this?your reply will be much appreciated
Its OK. I had a problem...could be a Mac thing. Instead of making a new line in the file, the text appeared in the file as "Hello\n", that is the special characters appeared in the file.
To get around the problem I changed the program to read:
That is, I put the special character directly in the second parameter. Then it created a new line.