I don't understand what is the problem.....i tried it, but get an error. So plz help me to solve the problem...
이전 댓글 표시
"Write a function called integerize that takes as its input a matrix A of non-negative integers of type double, and returns the name of the “smallest” unsigned integer class to which A can be accurately converted. If no such class exists, the string 'NONE' is returned. For example, if the largest integer A is 14, then the function would return 'uint8', but if the largest integer in A is 1e20, then the function would return 'NONE'."
답변 (5개)
Walter Roberson
2015년 5월 30일
1 개 추천
hint: log2()
Image Analyst
2015년 5월 30일
Hint: see functions intmax() and max()
mavValue = max(A(:))
if maxValue < intmax('uint8')
and so on...
댓글 수: 3
Muhammad Usman Saleem
2015년 6월 1일
@image i am using that code now , but getting the below mentioned error...
function integ=integerize(A)
mavValue = max(A(:))
if maxValue < intmax('uint8')
integ='uint8';
if maxValue<intmax('uint16')
integ='uint16';
if maxValue<intmax('uint32')
integ='uint32';
if maxValue<intmax('uint64')
integ='uint64';
else
integ='NONE';
end
end
end
end
Error i got is
Feedback: Your program made an error for argument(s) 0
Your solution is _not_ correct.
guide me where i need corrections.. Thanks in advance
Muhammad Usman Saleem
2015년 6월 1일
@image in another approach i use..
function integ=integerize(A)
if int(A) && uint(A)
if max(A)<=intmax('uint16')
integ='uint16';
elseif max(A) <= intmax('uint32')
integ='uint32';
elseif max(A) <= intmax('uint64')
integ='uint64';
elseif mod(A,1)=>0
integ='NONE';
end
end
end
but the error remains same as mentioned above..
Image Analyst
2015년 6월 1일
Muhammad, It looks like you've gotten your own thread started in this other thread so we'll just have the discussion over there.
Mostafa Farhoudi
2015년 7월 15일
편집: Walter Roberson
2015년 7월 16일
function integ=integerize(A)
integ = 'none';
maxValue=max(A(:));
disp(maxValue);
if maxValue <= intmax('uint8')
integ='uint8';
elseif maxValue<=intmax('uint16')
integ='uint16';
elseif maxValue <= intmax('uint32')
integ='uint32';
elseif maxValue <= intmax('uint64')
integ='uint64';
else
integ='NONE';
end
end
charu sharma
2015년 8월 20일
0 개 추천
Pranash Azrot
2015년 8월 25일
yaar mera answer teek see.
function u = integerize(A)
g =max(max(A));
if (g>255 && g<=intmax('uint16'))
u = 'uint16';
elseif (g<0 || g>intmax('uint64'))
u = 'NONE';
elseif (g>intmax('uint16') && g<=intmax('uint32'))
u = 'uint32';
elseif (g>intmax('uint32') && g<=intmax('uint64'))
u = 'uint64';
else
u = 'uint8';
end
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!