problem in saving array in txt file

조회 수: 2 (최근 30일)
huda nawaf
huda nawaf 2012년 4월 15일
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

채택된 답변

per isakson
per isakson 2012년 4월 15일
'%c' is single chracter. Try '%s'.
  댓글 수: 2
huda nawaf
huda nawaf 2012년 4월 15일
thanks,
what i I saved in file, then I want read it . why it read character y character.
R
C
I
.
ETC
I want raed it as:
RXIN AFGN........
huda nawaf
huda nawaf 2012년 4월 16일
what u suggested is saving as i need but when read it , it read character by character while i need each 4 characters as one character
thanks

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
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});
  댓글 수: 1
huda nawaf
huda nawaf 2012년 4월 16일
but i need it array with two rows and three columns as in array above

댓글을 달려면 로그인하십시오.


Jan
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);
  댓글 수: 1
huda nawaf
huda nawaf 2012년 4월 16일
thanks jan
but this is just example 2*3
what if have large dataset?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by