4.92

4.9 | 25 ratings Rate this file 201 Downloads (last 30 days) File Size: 2.28 KB File ID: #25387
image thumbnail

Write Cell Array to Text File

by Roland Pfister

 

22 Sep 2009 (Updated 12 Oct 2010)

A cell array is written to a delimited output file, incl. options for appending & custom delimiters.

| Watch this File

File Information
Description

This submission works similar as Sylvain Fiedlers / Rob Kohrs "cell2csv.m". Thus, any cell array containing numbers and/or strings can be written to an output file.

dlmcell.m, however, has two main advantages:

(1) It is possible to append the cell array to an existing file.

(2) Even numbers or words that are stored as <1,1> cell within the cell array can be read.

Acknowledgements

Cell2csv inspired this file.

This file inspired Flotation Kinetics Equation Fitting, Rosin Rammler Diagram Plotting Tool, and Image Quality Index Analysis Gui.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
append, array, cell, data, data export, delimited, dlmwrite, export, tools, utilities
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (30)
03 Jun 2013 Uni A

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.

Anu suggestions please? This is kinda urgent.

20 Mar 2013 Ricardo

works fine. thanks so much

24 Jan 2013 Robin  
10 Aug 2012 Rossella Blatt Vital

Great function! Love it!
Is there a way to add any formatting to the text? For example changing the font style (e.g., bold, oblique etc.) and the color?
Many thanks!

30 Jul 2012 Brad Stiritz

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(output_file,'%s',output{i,j});
------------------------------

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.

One star subtracted for each of these problems.

24 Jul 2012 Mango

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?

24 Jul 2012 Mango

Absolutely phenomenal. Only thing I could ask for would be a way to use something similar to the format %q that is available from textscan.

20 Jun 2012 Nolan C

Nice!

14 Jun 2012 Martin Schain

I encountered the same problem as sohrab, with \t printed in the file rather than tabs. I fixed it by replacing row 100 from
>>fprintf(output_file,'%s',delimiter);
to just
>>fprintf(output_file,delimiter);

Thanks for an excellent file!

08 Apr 2012 sohrab

\t is printed except of doing tab! what should i do?

05 Apr 2012 Alex  
22 Mar 2012 sharsad

Cool function. But using dlmcell I could only write the first element of my cell.
My cell is in the following format;
C =
[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

03 Jan 2012 none

excellent.

12 Dec 2011 daisy

Great function! We've had problem with cell2csv, thanks to dlmcell that solves our trouble!

07 Dec 2011 Evan

This is an extremely useful script (thank you!) but I'm running into a little problem executing from Linux - slashes are appended between the fields before an after the delimiter - any ideas?

Example output text:
\Filename\,\StartDate\,\EndDate\,\Number of Measurements\

03 Nov 2011 Michael Krause

Great function, works awesome, was clearly missing as a built-in. Well done. (gave it 5 stars, but it's not showing up in Chrome??)

13 Oct 2011 Ismael Seanez  
03 Aug 2011 Jane T

Like Matt I was having a problem with the '\t' appearing in the file. I'm running 2011a in Windows 7.
I changed line 100 to read 'fprintf(output_file,delimiter);'

05 Jul 2011 Michael

so awesome!

28 Jun 2011 Seth  
18 May 2011 Truc Phan

works great! thanks

12 May 2011 Matt Fetterman

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:
fprintf(fid,'%s\n',astring)
That is, I put the special character directly in the second parameter. Then it created a new line.

21 Jan 2011 Boris  
08 Dec 2010 Rossella Blatt

Very useful! Works perfectly! Thanks.

29 Aug 2010 Ivan Brezani

perfect, thanks!

27 May 2010 hugotang Tang

This function is good, thanks, man!

03 Dec 2009 Fabio Gori

It makes my life simpler!

01 Dec 2009 Russ Branaghan  
01 Nov 2009 Yonatan Cal

Thanks for this file!

28 Oct 2009 Jeff Evans

works perfectly! just as described.

Updates
12 Oct 2010

Little bugfix concerning %-signs.

Contact us