Not enough values for typecast

2 次查看(过去 30 天)
Aaron Smith
Aaron Smith 2017-3-8
编辑: Jan 2017-3-14
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 个评论
Adam
Adam 2017-3-8
编辑:Adam 2017-3-8
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.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2017-3-8
编辑:Jan 2017-3-14
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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by