[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: inconsistent results between textread and load
From: |
Philip Nienhuis |
Subject: |
Re: inconsistent results between textread and load |
Date: |
Sat, 15 Nov 2014 15:57:13 -0800 (PST) |
kamaraju wrote
> It looks like the same data file is read in different ways by textread
> and load. Is this intentional? If not, can we make the default
> behaviour consistent?
>
> Consider the following two data files
>
> address@hidden:~/x$ cat data.txt
> 1.0 2.0 NaN 3.0 4.0
> address@hidden:~/x$ cat data2.txt
> 1.0 2.0 NA 3.0 4.0
>
> address@hidden:~/x$ octave -q
> octave:1> a = textread("data.txt"); a
> a =
>
> 1
> 2
> NaN
> 3
> 4
>
> octave:2> a = load("data.txt"); a
> a =
>
> 1 2 NaN 3 4
>
> So textread is reading it as a 5x1 vector while load is reading it as
> 1x5 vector.
>
> octave:3> a = load("data2.txt"); a
> error: value on right hand side of assignment is undefined
> octave:3> a = textread("data2.txt"); a
> a =
>
> 1
> 2
> NA
> 3
> 4
>
> So 'load' is not able to handle NA but 'textread' is.
I'm not sure about "load" and NA. Hopefully other people here will comment
on that.
As to the output format (dimensions):
You made a data file consisting of one row. In that case textread, having
been given no format string, will by default read the numbers consecutively
and produce a 1-column output vector.
It would have been different had you supplied a format string "%f %f %f %f
%f".
To illustrate that, I've run your example with strread (the work horse
behind textread, for the outcome that doesn't matter):
>> [a] = strread ("1.0 2.0 NaN 3.0 4.0")
a =
1
2
NaN
3
4
>> [a, b, c, d, e] = strread ("1.0 2.0 NaN 3.0 4.0", "%f %f %f %f %f")
a = 1
b = 2
c = NaN
d = 3
e = 4
>> [a, b, c, d, e] = strread ("1.0 2.0 NaN 3.0 4.0 \n 5 6 7 NaN 8", "%f %f
>> %f %f %>
a =
1
5
b =
2
6
c =
NaN
7
d =
3
NaN
e =
4
8
I'd suggest to read up on textread's (strread's) format string and defaults.
Philip
--
View this message in context:
http://octave.1599824.n4.nabble.com/inconsistent-results-between-textread-and-load-tp4667360p4667362.html
Sent from the Octave - General mailing list archive at Nabble.com.