Print a cell arrays into text file

2 views (last 30 days)
Sergio
Sergio on 29 Aug 2013
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.

Answers (1)

Muthu Annamalai
Muthu Annamalai on 29 Aug 2013
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 Comment
Sergio
Sergio on 29 Aug 2013
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);

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!