problem in saving array in txt file
1 次查看(过去 30 天)
显示 更早的评论
hi, I want to save this array in file but I did not get what I want
ex.
x={'RCIN' 'AFGN' 'RGGA';'RCIN' 'RQDM' 'RGGA'};
in fact my data is more larger, but are of this type.
when run this code:
outfid=fopen('web.txt','wt');
for i=1:2
for j=1:3
fprintf(outfid, '%c ',x{i,j} );
end
fprintf(outfid,'\n' );
end
I get web.txt as
R C I N A F G N R G G A
R C I N R Q D M R G G A
But I need it as in array: 'RCIN' 'AFGN'.......
please, who can help me , I suffered from this problem since long time
thanks in advance, huda
0 个评论
采纳的回答
更多回答(2 个)
Image Analyst
2012-4-15
Looks right to me. You got the first row of the 2 by 3 cell array, which is 12 characters, on the first line, and the second row (second 12 characters) on the second line. That's an array of 2 rows and 12 columns. What's the issue? You also need to add an fclose(outfid);
If, by chance, you don't want the space between the characters, then just don't add one:
fprintf(outfid, '%c', x{i,j});
Jan
2012-4-15
x = {'RCIN' 'AFGN' 'RGGA';'RCIN' 'RQDM' 'RGGA'};
outfid = fopen('web.txt','wt');
if outfid == -1, error('Cannot open file'); end % Always check!
xt = transpose(x);
fprintf(outfid, '%s %s %s\n', xt{:});
fclose(outfid);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!