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}

1 件のコメント

Philip
Philip 2013 年 2 月 21 日
Great, thanks for the help! Worked perfectly.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by