Not enough values for typecast
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!