load hex data from a text file

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

load hex data from a text file

parafux
Hi,

i use matlab and octave on Linux.
I have a file test.txt with this content:

0xA 0xB
0xC 0xD

I load the data in matlab with this command:
x=load("test.txt")

I get this result, seems that the programmer implemented a fridays 13th joke

>> x
x =
10 11
12 14

I also try this load command in Octave, but get this error:
octave:18> x=load("test.txt");
error: load: failed to read matrix from file 'test.txt'

I was hoping to get an easy wey to load that hex values from file into a
variable.

can anymody help?



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: load hex data from a text file

apjanke-floss


On 10/25/19 2:40 AM, parafux wrote:

> Hi,
>
> i use matlab and octave on Linux.
> I have a file test.txt with this content:
>
> 0xA 0xB
> 0xC 0xD
>
> I load the data in matlab with this command:
> x=load("test.txt")
>
> I get this result, seems that the programmer implemented a fridays 13th joke
>
>>> x
> x =
> 10 11
> 12 14
>
> I also try this load command in Octave, but get this error:
> octave:18> x=load("test.txt");
> error: load: failed to read matrix from file 'test.txt'
>
> I was hoping to get an easy wey to load that hex values from file into a
> variable.
>
> can anymody help?

Hi parafux,

Could you attach the actual "test.txt" file to a reply email so we can
examine it? There's a lot of ambiguities here, and it'd be easiest to
debug if we could examine the actual file.

Cheers,
Andrew


Reply | Threaded
Open this post in threaded view
|

Re: load hex data from a text file

parafux
Reply | Threaded
Open this post in threaded view
|

Re: load hex data from a text file

apjanke-floss


On 10/25/19 3:59 AM, parafux wrote:
> test.txt <https://octave.1599824.n4.nabble.com/file/t370846/test.txt>  


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.

Can you tell us:

a) What version of Octave are you using?
b) How did you install Octave?
c) What OS and distribution are you using?

It sounds to me like you're doing the right thing and something odd is
happening.

Cheers,
Andrew


Reply | Threaded
Open this post in threaded view
|

Re: load hex data from a text file

parafux
to be honest, i am using this online version, because it is not allowed to
install it in our company.
https://octave-online.net/

Thank you for this information, i will go ahead and ask the guys there also.

but funny that matlab gives 14 instead of 13 and octave works well.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: load hex data from a text file

Pantxo
parafux wrote
> to be honest, i am using this online version, because it is not allowed to
> install it in our company.

If you are working on Windows, there is actually a "portable" (.zip) version
of Octave and IIUC you won't need any privilege to use it.

Pantxo




--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: load hex data from a text file

nrjank
> If you are working on Windows, there is actually a "portable" (.zip) version
> of Octave and IIUC you won't need any privilege to use it.

of course you should always follow software security policy at your
workplace and seek proper approvals before use.  ;)


Reply | Threaded
Open this post in threaded view
|

Re: load hex data from a text file

Mike Miller-4
In reply to this post by apjanke-floss
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'

--
mike



signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: load hex data from a text file

nrjank
On Fri, Oct 25, 2019 at 1:39 PM Mike Miller <[hidden email]> 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.


Reply | Threaded
Open this post in threaded view
|

Re: Re: load hex data from a text file

John W. Eaton
Administrator
On 10/25/19 1:46 PM, Nicholas Jankowski wrote:

> On Fri, Oct 25, 2019 at 1:39 PM Mike Miller <[hidden email]> 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 | Threaded
Open this post in threaded view
|

Re: Re: load hex data from a text file

Mike Miller-4
On Mon, Oct 28, 2019 at 16:07:54 -0400, John W. Eaton wrote:

> 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.
Yeah, you're right. It's another difference between the GCC and LLVM C++
iostreams implementations. I think this could be considered another
manifestation of https://bugs.llvm.org/show_bug.cgi?id=17782.

As a reminder, https://savannah.gnu.org/bugs/?47413 is a different
symptom, but similar underlying cause.

--
mike



signature.asc (849 bytes) Download Attachment