[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: newline in strread format
From: |
Daniel J Sebald |
Subject: |
Re: newline in strread format |
Date: |
Tue, 24 Jun 2014 03:15:40 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16 |
On 06/23/2014 10:57 PM, John W. Eaton wrote:
I think the following should work, but it's throwing an error:
octave:1> [a, b, c] = strread ("1 2 3\n4 5 6\n7 8 9\n", "%f %f %f\n")
strread: FORMAT does not match data
error: called from 'strread' in file
/home/jwe/src/octave-stable/scripts/io/strread.m near line 745, column 13
error: called from:
error: /home/jwe/src/octave-stable/scripts/io/strread.m at line 755,
column 9
I took a look at strread.m but I'm not sure what the right approach is
for a fix. It appears to me that newlines are removed from the string
and that it is split on the field delimiter. But the newline
character remains in the list of format specifiers.
I noticed the problem in the stable sources, but it seems to also be
present in the current sources on the default branch.
Any clues would be much appreciated.
I suppose that "\n" could in theory be a valid literal. That's where
the interpretation part of this routine is failing, i.e., "\n" as not
being accepted as a literal. Consider that the following works:
octave:3> [a, b, c] = strread ("1 2 3L\n4 5 6L\n7 8 9L\n", "%f %f %fL")
a =
1
4
7
b =
2
5
8
c =
3
6
9
The newline character is always the character that can be treated as a
"new line" in the data string. That is, if we replace literal "L" with
"\n":
[a, b, c] = strread ("1 2 3\n\n4 5 6\n\n7 8 9\n\n", "%f %f %f\n")
one would think that we should get the same result. (Notice the two
newline characters in the data string.) But that fails as well.
octave:4> [a, b, c] = strread ("1 2 3\n\n4 5 6\n\n7 8 9\n\n", "%f %f %f\n")
strread: FORMAT does not match data
error: called from 'strread' in file
/usr/local/src/octave/octave-for_loop_test/build-dev/../octave-dev/scripts/io/strread.m
near line 745, column 13
error: called from:
error:
/usr/local/src/octave/octave-for_loop_test/build-dev/../octave-dev/scripts/io/strread.m
at line 755, column 9
One could maybe make sense of the single literal newline characters in
the following way:
octave:4> [a, b, c, d, e, f, g, h, i] = strread ("1 2 3\n4 5 6\n7 8
9\n", "%f %f %f\n%f %f %f\n%f %f %f\n")
warning: strread: unable to parse text or file with given format string
warning: called from
strread at line 659 column 7
error: element number 1 undefined in return list
but as seen above, that fails too.
Dan