help-octave
[Top][All Lists]
Advanced

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

Thanks Re: Loading hex data


From: ionavideo
Subject: Thanks Re: Loading hex data
Date: Mon, 17 Sep 2012 07:41:19 -0700 (PDT)

Thanks. I really appreciate the suggestions. I tried both dlmread and textread. With textread I get an "error" I can sort of work with.

Here is the data file keydata.txt:
32
51
0b
a9
ba

So we have 5 hexadecimal numbers separated by CR-LF

And here is the Octave line:

k= hex2dec(textread("keydata.txt", "%d"))

And the output from running the test program is:
k =
    0
    3
    0
    0
    0
   
Which is not a correct translation of "32 51 0b a9 ba" because
32 hex equals 50 dec or the ascii "2"
and 51 hex equals dec 81 or ascii "Q", etc.

Yes, I tried other ways to format the line, as follows:

#k= hex2dec(textread("keydata.txt", "%x"))
# the above gives "error: Invalid call to hex2dec. Correct usage is hex2dec(S)

#k= hex2dec(textread("keydata.txt", "%s"))
#the above gives several errors, including: 'string undefined ... called from
# ... toascii.m
# error evaluating argument list element number 1
# error ... strjust.m
# error ... base2dec.m
# errpr ... hex2dec.m
---------------------------------------------------------
So my question is, should I be using
    %s
or
    %d
to format a hex2dec function call of a textread of a hex file
AND
if I should be using %s, what do I need to do to make the line work?

thanks.


--- On Thu, 9/13/12, Jordi GutiƩrrez Hermoso-2 [via Octave] <[hidden email]> wrote:
The load command is for reading files in Matlab or Octave format.
Instead try something like

    x = hex2dec(textread("data.txt", "%s"));

HTH,
- Jordi G. H.

If you reply to this email, your message will be added to the discussion below:
To unsubscribe from Loading hex data, click here.
NAML


View this message in context: Thanks Re: Loading hex data
Sent from the Octave - General mailing list archive at Nabble.com.

reply via email to

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