# Does Simulink offer any block that can tell me if the input is signed or unsigned ?

2 visualizaciones (últimos 30 días)
Diaa Younes el 31 de En. de 2022
Comentada: Diaa Younes el 1 de Feb. de 2022
Hello,
I am using Simulink/Embedded Coder and I was implementing a subsytem that needs to know if one of its inputs is signed or unsigned.
is there a block/function that can tell if an input is signed or unsinged? For example if the type of the input is Uint8, Uint16,Uint32 then the output of the block will be 0, and if the type is Int8, Int16, Int32 the block will be 1, let's say.
Thank you
Diaa
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Paul el 31 de En. de 2022
Editada: Paul el 1 de Feb. de 2022
Does the subsystem in question behave fundamentally differently for a signed input compared to an unsigned input?
Diaa Younes el 1 de Feb. de 2022
yes and that's why I needed it

Iniciar sesión para comentar.

### Respuestas (1)

Benjamin Thompson el 31 de En. de 2022
There is a block in the Math Operations library called "Sign".
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
Benjamin Thompson el 31 de En. de 2022
The Signal Attributes library in Simulink has blocks similar to what you are asking for, such as data type inheritance, data type propagation. Or you could use a MATLAB Function block and use the "isa" functions to check on the type of the incoming inputs: isinteger, isnumeric.
isa(uint32(3), 'uint32')
ans =
logical
1
Diaa Younes el 1 de Feb. de 2022
Your suggsetion of having a function block and the "isa" seems to be the solution. I tried it, it works; at least in simulation. I am yet to try to see if embeded coder will be fine with.
function y = fcn(u)
y = isa(u, 'uint8') || isa(u, 'uint16') || isa(u, 'uint32') || isa(u, 'uint64') ;
The Simulink signal attribute block didn't seem to help.
Diaa

Iniciar sesión para comentar.

### Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

R2010b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by