problem with dlmwrite

hi, I have :
aa1=[aa(1) aa(2) aa(3) aa(4) ];
aaseq(i,k2)={aa1};
dlmwrite('d.txt',aaseq);
I got this error:
??? Error using ==> dlmwrite at 112 The input cell array cannot be converted to a matrix.
how solve this problem?
thanks in advance

답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 12월 6일

0 개 추천

Don't convert it to a cell array with the {}.

댓글 수: 4

huda nawaf
huda nawaf 2011년 12월 6일
Thanks,
I used {} because aa1 is :
'acsd'
and I want to place 'acsd' in aaseq(1,1) for example and so on, then store it in file.
how get that
Sean de Wolski
Sean de Wolski 2011년 12월 6일
Not with dlmwrite/read.
Sean de Wolski
Sean de Wolski 2011년 12월 6일
Why note just save it to a matfile:
doc save
?
huda nawaf
huda nawaf 2011년 12월 6일
i did
s='m.mat'
for ex. x={'gh' 'kl'};
save(s,'x')
but when click on m.mat file did not opened

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

Walter Roberson
Walter Roberson 2011년 12월 6일

0 개 추천

댓글 수: 4

huda nawaf
huda nawaf 2011년 12월 7일
thanks
i visited these links,and follow your suggestion
dlmwrite('k.txt', aaseq, 'delimiter', '', 'precision', '%c ');
aaseq =
'?RKG' 'RCRE' '?RFI' '???Q' 'AGQI' 'RIEE' 'RCIN'
'??HG' 'RKC?' 'AMLG' 'RGHI' 'RCIN' 'RQDM' 'RGGA'
ok, i got file as
?RKGRCRE?RFI???QAGQIRIEERCINAFGNRGGARDLR
??HGRKC?AMLGRGHIRCINRQDMRGGA?RGH?FP?RQL?
but when use dlmread
??? Undefined function or method 'dlmwread' for input arguments of
type 'char'.
huda nawaf
huda nawaf 2011년 12월 7일
unfortunately, the dlmwrite ran in command window just , when i used the original file, the problem is still
?? Error using ==> dlmwrite at 112
The input cell array cannot be converted to a
matrix.
Walter Roberson
Walter Roberson 2011년 12월 7일
Remember that when you use that code, you need to explicitly add any commas you want between elements.
I do not recommend using dlmwrite for character data: I only devised the code to do it because someone said it couldn't be done at all and I was feeling contrary.
If you want to write a cell array of strings in delimited form, you should use code such as
fid = fopen('k.txt','wt');
fmt = [ repmat('%s,', 1, size(aaseq,2)-1), '%s\n' ];
fprintf(fid, fmt, aaseq{:});
fclose(fid)
If you want double-quotes to appear around every string field, then modify the fmt line to
fmt = [ repmat('"%s",', 1, size(aaseq,2)-1), '"%s"\n' ];
huda nawaf
huda nawaf 2011년 12월 8일
thanks
i got file as I want when use what u suggested:
sdf,fgh
dfg,jkl
now, I want to read it
now i can read it by dlmread,right?
if so, why I got this error
??? Error using ==> dlmread at 145
Mismatch between file and format string.
Trouble reading number from file (row 1, field 1) ==> sdf,f

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

카테고리

태그

질문:

2011년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by