Write a cell array to a text file

バージョン 1.1.0.1 (2.34 KB) 作成者: Ameya Deoras
Write formatted data from a cell array to a text file
ダウンロード: 2K
更新 2016/9/1

ライセンスの表示

This function enables you to directly write data from a cell array into a text file, which functions like FWRITE and FPRINTF do not.
Usage:

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.

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.

Example:
fwritecell('textfile1.txt', '%2d %1d %21s %8.5f', C);
See detailed example below.

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);

引用

Ameya Deoras (2024). Write a cell array to a text file (https://www.mathworks.com/matlabcentral/fileexchange/21800-write-a-cell-array-to-a-text-file), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2008a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.1.0.1

Updated license

1.1.0.0

No code change, just description update

1.0.0.0