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 Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by