Not enough values for typecast
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm attempting to use discretize to bin a large matrix. The problem is that the values are in int32 format. I am attempting to convert the data to uint32 using typecast but the "not enough arguments" arises. What do I need to change or specify to rectify this?
1 commentaire
Adam
le 8 Mar 2017
Modifié(e) : Adam
le 8 Mar 2017
It would help if you show your code otherwise we don't know what you are doing wrong.
Can you not just cast using e.g.
output = uint32( input );
? I'm not sure typecast is really what you want to be using. Also if you have negative data this will all get lost if you just cast so you would need to scale and shift your data.
Réponses (1)
Jan
le 8 Mar 2017
Modifié(e) : Jan
le 14 Mar 2017
Casting means changing the values to match the new type:
a = int32([15, -1])
b = uint32(a) % Equivalent: cast(a, 'uint32')
Now b is [15, 0]: The first value is kept, but the second is set to 0 because it is the nearest possible conversion.
With typecasting the bitpatterns are not touched, such that the values can change:
typecast(a, 'uint32')
>> [15 4294967295]
This needs two inputs (seeing your code would reveal what is missing) and the value of uint32(-1) is changed.
[EDITED] Typecasting a vector of 3 uint8 values:
x = uint8(1:3)
to an uint32 must fail, because the input contains to few bytes. A multiple of 4 bytes are required for this operation. This causes the error "Not enough values for typecast".
I assume, you want to cast the values, not to typecast.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!