Print a cell arrays into text file

조회 수: 4 (최근 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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by