Borrar filtros
Borrar filtros

Array type effected by variable type

1 visualización (últimos 30 días)
Melih Furkan SEN
Melih Furkan SEN el 4 de Sept. de 2023
Respondida: Riya el 7 de Sept. de 2023
x=uint64(5);
c=[-2,x];
c becomes [0,5] because c = uint64 array.
So I dont want it to be effected by input types. I want c=[-2,5]
how do I do that?
  1 comentario
Dyuman Joshi
Dyuman Joshi el 4 de Sept. de 2023
Editada: Dyuman Joshi el 4 de Sept. de 2023
Numeric arrays (in MATLAB) are always homogenous. When you concatenate values of multiple (2 or more) numeric data types, the final data type would be the one of the left most integer (If present) or single (if only single and double are present)
"So I dont want it to be effected by input types."
Things don't work that way in MATLAB.
"how do I do that?"
Instead of unsigned integers, use signed integers or double or single data types. Take into consideration the difference of ranges and other specifications of each data type.

Iniciar sesión para comentar.

Respuestas (1)

Riya
Riya el 7 de Sept. de 2023
Hello Melih Furkan SEN,
As per my understanding, you don’t want that array type is affected by variable type.
Please note that, if you want to create an array `c` with the values [-2, 5] regardless of the input type of `x`, you can convert `x` to a double before creating the array. Here's how you can achieve that:
x = uint64(5);
c = [-2, double(x)];
By using the `double` function, you can convert `x` to a double precision floating-point number, which allows it to be combined with other double values in the array `c`. This way, the resulting array `c` will have the desired values [-2, 5] without being affected by the input type of `x`.
You can refer the following documentations to know more:
I hope it helps!

Categorías

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

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by