Be the first to rate this file! 11 downloads (last 30 days) File Size: 2.34 KB File ID: #21800

fwritecell

by Ameya Deoras

 

17 Oct 2008 (Updated 17 Oct 2008)

Code covered by BSD License  

Write formatted data from a cell array to a text file.

Download Now | Watch this File

File Information
Description

Functions such as FWRITE and FPRINTF do not offer the ability to directly write data from a cell array to a text file. This is where this function comes in.

fwritecell(filename, format, data) writes cell array "data" to the file with name "filename" using the C language conversion specifications in argument "format". The conversion specifications are the same as those used by SPRINTF.
Example syntax:
fwritecell('textfile1.txt','%2d %1d %21s %8.5f',C);
See detailed example below.

fwritecell(filename, data) writes cell array "data" using a fixed width format padded with whitespace. The field widths are determined automatically. Note that the decimal point for floating point numbers may not be aligned within columns.

The ZIP file contains fwritecell.m and fwritecell_example.m which contains the following code:

Example:

C={ 1, 2, 'hello', 3.45
   34, 2, 'this is a long string', 4
    2, 4, 'g', 24.13312};

% Recommended approach specifying field widths
% example %8.5f implies: at least 8 characters long
% with 5 after the decimal point
fwritecell('textfile1.txt','%2d %1d %21s %8.5f',C);

% Write fixed width. Note that the decimal points are not
% lined up
fwritecell('textfile2.txt',C);

% This call is similar to the first one, but note that the
% columns do not have a fixed width.
fwritecell('textfile3.txt','%d, %d, %s, %f',C);

MATLAB release MATLAB 7.6 (R2008a)
Zip File Content  
Other Files fwritecell_example.m,
fwritecell.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
data import Ameya Deoras 22 Oct 2008 10:25:08
data export Ameya Deoras 22 Oct 2008 10:25:08
utilities Ameya Deoras 22 Oct 2008 10:25:08
data Ameya Deoras 22 Oct 2008 10:25:08
functions Ameya Deoras 22 Oct 2008 10:25:08
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com