Error using ==> fprintf Function is not defined for 'cell' inputs.

Can anyone point out what's wrong with my code? I'm trying to print information to a file with fprintf. I keep getting the error: "Error using ==> fprintf Function is not defined for 'cell' inputs."
fid= fopen('conf1.txt');
fid1=fopen('conf.txt');
fid2=fopen('new_conf.txt','w');
N = 2703;
A = textscan(fid, '%d %s %s %d %f %f %f', N, 'headerlines', 2);
C = textscan(fid1, '%d %s %s %d %f %f %f %f %f %f', N, 'headerlines', 2);
for i = 1:2703
fprintf(fid2,'%5d%5s%5s%5d%8.3f%8.3f%8.3f%8.4f%8.4f%8.4f \r\n', C{1}(i), C{2}(i), C{3}(i), C{4}(i), A{5}(i), A{6}(i),A{7}(i),C{8}(i),C{9}(i),C{10}(i));
end
fclose all ;

 채택된 답변

Walter Roberson
Walter Roberson 2013년 2월 21일

1 개 추천

textscan returns a cell array with one entry per column. When the column use a string format, the entry is a cell array of strings -- so you have to index the result of textscan as a cell array to get the cell array and you have to index that as a cell array in order to get out a string. Thus, change C{3}(i) to C{3}{i}

추가 답변 (0개)

카테고리

도움말 센터File 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