how can i convert decimal to hex in simulink?
Show older comments
Hello everybody,
I wanted to convert a decimal value into HEX in Simulink using a matlab function. Unfortunately I get an error: Data 'y' (# 115) is inferred as a variable size matrix, while its specified type is something else. Can someone help please?


1 Comment
JD Harwell
on 16 Aug 2019
Did you find a solution to this? I am in need of the same.
Answers (1)
Walter Roberson
on 22 Feb 2019
dec2hex() produces a character vector result. Character vectors cannot be carried as signals in Simulink. The closest you can get is to take send the codes for the characters and char() that later when you need to convert back to text.
y = dec2hex(u) + 0;
You should also be concerned about the signal length: dec2hex produces variable length output.
You might want to consider
y = uint8(dec2hex(u, 16) - '0');
changing the 16 to the number of digits appropriate for the situation.
3 Comments
JD Harwell
on 16 Aug 2019
I am trying this:
y = uint8(dec2hex(u, 16) - '0');
in a "MATLAB Function" Simulink block but keep getting an error:
Size mismatch error on dimension 2: expected 1, but actual size is 4.
I changed the 16 to 4 as that is the size of hex I need, but I cannot figure out why it is expecting a size of 1.
Could you advise on this?
mohammad ahmad
on 10 Feb 2021
how to convert decimal matrix(16*16) to hexa in matlab
Walter Roberson
on 11 Feb 2021
compose("%x", YourMatrix)
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!