From: Paul K. <pki...@us...> - 2005-05-29 14:45:22
|
In the past my solution to the fread problem has been to append a transposition operator ' to the fread call. Looking at recent matlab docs, it looks like you can specify '*char' or 'char=>char'. I don't know if that fixes the orientation problems though. Do you know if the strtok problem exists a lot of places in the wild? If so, we should probably adapt strtok to handle it. Note that recent versions of strtok on matlab are documented to take cell arrays. Matrices of characters as a representation for a list of strings was never a good representation. - Paul On May 29, 2005, at 8:59 AM, Tom Holroyd wrote: > On Sat, 28 May 2005, Paul Kienzle wrote: > >> An m x 1 vector of characters should be interpreted as an array of >> length one strings. > > Good point. strcmp treats an m x n string array as m strings. > > Of course strtok doesn't work for string arrays, either: > > octave:4> s = ['abca';'fdag']; > octave:5> strtok(s, 'a') > error: mx_el_ne: nonconformant arguments (op1 is 3x1, op2 is 1x3) > > With my patch the result is the somewhat non-obvious > > octave:1> s = ['abca';'fdag']; > octave:2> strtok(s, 'a') > ans = fbdc > > That's wrong, too. It should be ['bc';'fd'], and I guess in the case > where the result has different length rows the short ones should be > padded with blanks. > > One could certainly argue that fread with 'char' should return > strings, but since fread is documented as returning columns, for the > other types this doesn't make sense. The default is uchar, > too. > > Perhaps the documentation for fread could include a statement that if > you specify 'char', you probably also want to transpose the output, to > make it into a "string". Or a new 'string' type, as opposed to > 'char', that does this. > > Dr. Tom Holroyd > "A man of genius makes no mistakes. His errors are volitional and > are the portals of discovery." -- James Joyce > |