Why dlmread do not work with dlmwrite?

2 Ansichten (letzte 30 Tage)
huda nawaf
huda nawaf am 10 Dez. 2011
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 Kommentare
huda nawaf
huda nawaf am 10 Dez. 2011
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 am 10 Dez. 2011
As already explained, but I have expanded my answer to discuss this pointer further.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 10 Dez. 2011
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.

Community Treasure Hunt

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

Start Hunting!

Translated by