help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: load hex data from a text file


From: John W. Eaton
Subject: Re: Re: load hex data from a text file
Date: Mon, 28 Oct 2019 16:07:54 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

On 10/25/19 1:46 PM, Nicholas Jankowski wrote:
On Fri, Oct 25, 2019 at 1:39 PM Mike Miller <address@hidden> wrote:

On Fri, Oct 25, 2019 at 04:15:15 -0400, Andrew Janke wrote:
Well, that's interesting and somewhat surprising. In both Octave 4.4.1
and 5.1.0 on macOS 10.14.6, I get the following:

x = load('test.txt')
x =
     10    11
     12    13

Which is I think what you were expecting.

Really? That's weird, because I get

     >> x = load ('test.txt')
     error: load: failed to read matrix from file 'test.txt'


same here.  tried playing with a bunch of options and other textfile
input functions (outside manual c-type functions) and couldn't get it
to work.

Same here. When I traced the execution of the load function, it ends up in the octave_read_fp_value function defined at line 247 in lo-utils.cc and tries to read a double value with the istream >> operator (that's line 292 in the linked version of the file):

http://hg.savannah.gnu.org/hgweb/octave/file/5aad387784aa/liboctave/util/lo-utils.cc#l243

If the next characters on the input stream are "0xA", then unless I've specifically set the stream up to read hex values, I would expect to get a value of "0" with the next character to read being "x". That's what happens for me, then the next read operation fails because the input is "x". That some people are getting other results here might be be due to differences in the iostream library? If we want to fix this for compatibility with Matlab, then the functions in lo-utils.cc should be extended with a special case to recognize hex values, similar to the way that they currently do extra work to recognize Inf and Nan values.

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]