Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Matlab] dec2hex and sprintf problem?

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
matlab dec2hex

Hi all,

I want to convert a vector of dec to hex and sprintf to a string.
The code is:
%%-------------
data=[11 6 18 14];
sprintf('%c ',dec2hex(data))
%%------------
The output is
ans =

0 0 1 0 B 6 2 E

But what I want is "B 6 12 E", why the output of sprintf shuffle the data?

BTW, I use Matlab 5.3.
Any suggestions will be appreciated!
Best regards,
Davy
 

matlab sprintf dec2hex

For some reason, Matlab loves to work in columns. dec2hex will output each converted data on it's own line. The sprintf commands is no exception and thus will take the given data by columns. If we take the output of dec2hex([11 6]) for example, Matlab gives us:

ans =
0B
06

Which is then taken into sprintf by columns giving 0 0 B 6. If you try dec2hex([11 6])' the result would be:

ans =
00
B6

Giving an sprintf result of 0 B 0 6. Now there is a problem with what you are trying to do; dec2hex([18 14])' outputs:

ans =
10
2E

Which results as 1 2 0 e in sprintf. The dec2hex command outputs a string.

Hope this helps.

tcn
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
dec2hex vector matlab

data=[11 6 18 14];
sprintf('%X ', data)
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top