Hey,
I have wave signal that change between 2-20 and it's type of dubble. I need to convert it to type uint8, for example:
The wave signale is INDX(change from 2 to 20) type of dubble. Convert signal is: ADR = uint8(INDX);
the result of that conversion gives me values from 0 to 20. Even when ADR is runs from 0 to 18 or 1 to 19 I get the same result : ADR = 0 to 20 ?
Is it possible to get the same values of INDX after using INDX input ? for example, if INDX is running from 3 to 17, the result (ADR=uint8(INDX)) will be 3 to 17 instead 0f 0 to 20 ? or, if INDX is running from 2 to 18, the result (ADR=uint8(INDX)) will be 2 to 18 instead 0f 0 to 20 ? or, if INDX is running from 2 to 20, the result (ADR=uint8(INDX)) will be 2 to 20 instead 0f 0 to 20 ?
I need to keep the same values of the start and end(of INDX) after using uint8(INDX). uint8 type ,must be use.
Thanks, Henry

 채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 18일

0 개 추천

You must have made a mistake somewhere.
>> uint8(3:17)
ans =
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
In the expression 3:17 the values are double precision values, so this shows that converting double precision values to uint8 works as expected for small non-negative values.

댓글 수: 5

Henry Buck
Henry Buck 2016년 9월 18일
편집: Stephen23 2016년 9월 18일
Hi,
well, that's the problem: the values of INDX are not a vector as you wrote.
INDX = round(A/B). B is a constant - let say 40. A is kind a sine wave - max value is 800 and min value is 0 - that gives INDX is between 0 to 20 In other case it couild be 90 to 700 - that gives INDX between 2 to 18..
whent I am using uint8(INDX), it gave me 21 values - 0 to 20.
Why is that ?
thanks, Henry
Stephen23
Stephen23 2016년 9월 18일
@Henry Buck: please show us exactly the 21 values with this behavior, and how you are converting them to uint8. Then we can explain what is happening.
Image Analyst
Image Analyst 2016년 9월 18일
편집: Image Analyst 2016년 9월 18일
Is it possible you use im2double() somewhere along the way? That might rescale and shift things. gray2mat() also scales and shifts to the 0 to 1 range. Also, uint8 rounds internally. It does not just chop off the fractional part.
Like everyone else is saying, you need to show more code, or at least a small similar example, like Walter did, that proves what you're saying.
Not being a vector is irrelevant.
>> A = 53*(reshape(3:17, 3, 5) + rand(3,5)); B = 48; INDX = uint8(A/B)
INDX =
4 8 10 14 17
5 9 12 15 19
6 9 13 16 19
Henry Buck
Henry Buck 2016년 9월 18일
hey guys,
I have to be honest. It is my mistake.
Thanks again.
Henry

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2016년 9월 18일

댓글:

2016년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by