Print a cell arrays into text file

2 ビュー (過去 30 日間)
Sergio
Sergio 2013 年 8 月 29 日
I have a 1x8 Cell array composed of (2)cell array columns, (1)int32 column and (5) double. they are all the same size 417x1. I want to print this into a text file. I've been using fprintf but get disorganized data file. I would appreciate your input.

回答 (1 件)

Muthu Annamalai
Muthu Annamalai 2013 年 8 月 29 日
You want to try and use '%04d' '%10s' to print 4 digit integers, and 10 letter strings, i.e. use a maximum limit, and fixed width specifiers. For more details, type >> doc fprintf
  1 件のコメント
Sergio
Sergio 2013 年 8 月 29 日
Muthu,
Thank for your answer but I still can't get it to work. Its outputting everything in one line. I would like to have a delimited file with 8 columns, one for each variable.
Here is the code
clear all clc
fid=fopen('C:\Users\sdehoyos\Documents\Matlab Work\automating\Accotink_2and10yr_New_node_convention_2.inp','r'); textData=textscan(fid,'%s%d%s%f%f%f%f%f',417,'headerlines',46,'delimiter','\t'); fclose(fid);
a=textData{1,1}; b=textData{1,2}; c=textData{1,3}; d=textData{1,4}; e=textData{1,5}; f=textData{1,6}; g=textData{1,7}; h=textData{1,8};
fileID = fopen('blah.txt','w'); fprintf(fileID,'%12s%01d%05s%f%f%f%f%f\n','a','b','c','d','e','f','g','h'); fclose(fileID);

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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by