fprintf for cell array data

8 ビュー (過去 30 日間)
sermet OGUTCU
sermet OGUTCU 2021 年 11 月 18 日
コメント済み: Yongjian Feng 2021 年 11 月 18 日
data_double = 32 x 7 double
fprintf(fid,'%02d %.3f %.3f %.3f %.3f %.3f %.3f\n', data_double.');
It prints the data_double in a text file with 32 rows and 7 columns.
I have a cell data consists of char and double columns as follows:
data_cell=
1×3 cell array
{32×3 char} {32×3 double} {32×3 double}
I need to print this data_cell in a text file using the similar type as print of data_double (i.e, 32 rows and 7 columns). When I tried;
fprintf(fid,'%02s %.3f %.3f %.3f %.3f %.3f %.3f\n', data_cell.');
Error using fprintf
Function is not defined for 'cell' inputs.

採用された回答

Yongjian Feng
Yongjian Feng 2021 年 11 月 18 日
Try to convert your cell data into char first.
char(the_cell_you_want_to_print)
  2 件のコメント
sermet OGUTCU
sermet OGUTCU 2021 年 11 月 18 日
char(data_cell) gave this error:
Error using char
Cell elements must be character arrays.
Yongjian Feng
Yongjian Feng 2021 年 11 月 18 日
Maybe you want to list out the cell one by one like this:
fprintf(fid,'%02d %.3f %.3f %.3f %.3f %.3f %.3f\n', data_double{1}, num2str(data_double{2}), num2str(data_double{3}), num2str(data_double{4}), num2str(data_double{5}), num2str(data_double{6}), num2str(data_double{7}));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by