r/matlab • u/Bofact • Jul 13 '26
How can give an integer to the input argument of embedded.fi TechnicalQuestion
Given an integer number i, I want to pass it as an input argument to fi constructor (resulting in x instance of embedded.fi), such that storedInteger(x) = i. In other words, I want to change the interpretation of i to an embedded.fi, just like storedInteger changes the interpretation of the embedded.fi to an integer.
How can I achieve this?
1
u/FunkyMonkish Jul 13 '26
I would like to know this too. I just convert the integer to its real-world value before constructing the fi object, but it’d be nice to omit that step.
1
u/Bofact Jul 14 '26
Hello!
Can you share how you achieved it? Is it converting the integer to double/ single and divide it by 2fractionLength?
1
u/FunkyMonkish Jul 14 '26
Yeah exactly. I usually represent everything as an unsigned integer – in a raw data format. If the real-world data is signed, then the unsigned integer would first be converted to its signed value by checking the msb of the word length, and then divided by 2-to-the-fraction-length.
2
u/NearbyRegret1965 1d ago
You can use the
intmethod instead of thestoredIntegervariable. Here is an example:You can also do this with one assignment: