Why dlmread do not work with dlmwrite?

hi, I wrote symbols to file using dlmwrite, where the file became:
?,R,M,G,f,D,[],[]
W,E,R,R,T,U,H,K
N,D,F,[],[],[]
when tried to read it with dlmread , I got :
??? Error using ==> dlmread at 145
Mismatch between file and format string.
Trouble reading number from file (row 1, field 1) ==> ?,R,K
thanks

댓글 수: 4

Jan
Jan 2011년 12월 10일
Please post the code you have been using for writing and reading.
huda nawaf
huda nawaf 2011년 12월 10일
simple ex.
x=['qwe', 'ert','jkl';'rty', 'yui','oip'];
dlmwrite('f.txt',x);
d=dlmread('d:\matlab11\r2011a\bin\f.txt')
??? Error using ==> dlmread at 145
Mismatch between file and format string.
Trouble reading number from file (row 1, field 1) ==> q,w,e
huda nawaf
huda nawaf 2011년 12월 10일
simple ex.
x=['qwe', 'ert','jkl';'rty', 'yui','oip'];
dlmwrite('f.txt',x);
d=dlmread('d:\matlab11\r2011a\bin\f.txt')
??? Error using ==> dlmread at 145
Mismatch between file and format string.
Trouble reading number from file (row 1, field 1) ==> q,w,e
Walter Roberson
Walter Roberson 2011년 12월 10일
As already explained, but I have expanded my answer to discuss this pointer further.

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

답변 (1개)

Walter Roberson
Walter Roberson 2011년 12월 10일

0 개 추천

dlmread() can only read numeric data.
You have to cheat with dlmwrite() in order to write character data with it: it is not designed to write characters.
I did firmly say that I do not recommend that you use dlmwrite() to write character data, and that I only came up with the method to be contrary when someone said that it could not be done. I think I showed the code for the fopen / fprintf / fclose alternative.
[added]
When I said that dlmread can only read numeric data, I meant exactly that. It states this clearly in the documentation:
Tips
All data in the input file must be numeric. dlmread does not read files that contain nonnumeric data, even if the specified rows and columns contain only numeric data.
I have also examined the code that it uses; it uses an undocumented facility, but there is no doubt through testing that the facility will ONLY read numeric data.

카테고리

질문:

2011년 12월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by