フィルターのクリア

HELP ME PLEASE??

3 ビュー (過去 30 日間)
SULE SAHIN
SULE SAHIN 2017 年 11 月 6 日
コメント済み: Walter Roberson 2018 年 4 月 27 日
Write a function called integerize that takes as its input a matrix A of integers of type double, and returns the name of the “smallest” signed integer class to which A can be converted without loss of information. If no such class exists, the text 'NONE' is returned. For example, if the smallest element of A is -100 and the largest is +100, then the function would return 'int8'. As another example, if there is an element of A equal to -1e20, then the function would return 'NONE'
My code is;
function x = integerize(A)
maxA = max(A(:));
minA = min(A(:));
if maxA<=((2^7)-1) && minA>=-(2^7);
x='int8';
elseif maxA<=((2^15)-1) && maxA>((2^7)-1) && minA>=-(2^15) && minA< -(2^7);
x='int16';
elseif maxA<=((2^31)-1) && maxA>((2^15)-1) && minA >=-(2^31) && minA <-(2^15);
x='int32';
elseif maxA<=((2^63)-1) && maxA>((2^31)-1) && minA >=-(2^63) && minA< -(2^31);
x='int64';
else
x=NONE;
end
end
But it is noncorrect;
Problem 1 (integerize):
Testing with argument(s) 0
Feedback: Your function performed correctly for argument(s) 0
Testing with argument(s) 1
Feedback: Your function performed correctly for argument(s) 1
Testing with argument(s) -1
Feedback: Your function performed correctly for argument(s) -1
Testing with argument(s) -127
Feedback: Your function performed correctly for argument(s) -127
Testing with argument(s) -128
Feedback: Your function performed correctly for argument(s) -128
Testing with argument(s) 126
Feedback: Your function performed correctly for argument(s) 126
Testing with argument(s) 127
Feedback: Your function performed correctly for argument(s) 127
Testing with argument(s) 128
Feedback: Your program made an error for argument(s) 128
Your solution is _not_ correct.
I dont understant my fault pleas help me
  4 件のコメント
SULE SAHIN
SULE SAHIN 2017 年 11 月 6 日
編集済み: Walter Roberson 2017 年 11 月 6 日
What is the problem? My code is;
function x = integerize(A)
maxA = max(A(:));
minA = min(A(:));
if maxA<=((2^7)-1) && minA>=-(2^7);
x='int8';
elseif maxA<=((2^15)-1) && maxA>((2^7)-1) && minA>=-(2^15) && minA< -(2^7);
x='int16';
elseif maxA<=((2^31)-1) && maxA>((2^15)-1) && minA >=-(2^31) && minA <-(2^15);
x='int32';
elseif maxA<=((2^63)-1) && maxA>((2^31)-1) && minA >=-(2^63) && minA< -(2^31);
x='int64';
elseif maxA<= ((2^8)-1) && minA >= 0;
x = 'uint8';
elseif maxA<= ((2^16)-1) && maxA >((2^8)-1);
x = 'uint16';
elseif maxA<= ((2^32)-1) maxA > ((2^16)-1) ;
x = 'uint32';
elseif maxA<= ((2^64)-1) && maxA > ((2^32)-1) ;
x = 'uint64';
else
x=NONE;
end
end
But , it is wrong too.
Walter Roberson
Walter Roberson 2018 年 4 月 27 日
Please do not close questions that have an answer.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 11 月 6 日
You are only returning the signed integer classes. You have forgotten the unsigned integer classes like uint8
  2 件のコメント
SULE SAHIN
SULE SAHIN 2017 年 11 月 6 日
編集済み: Walter Roberson 2017 年 11 月 6 日
function x = integerize(A)
maxA = max(A(:));
minA = min(A(:));
if maxA<=((2^7)-1) && minA>=-(2^7);
x='int8';
elseif maxA<=((2^15)-1) && maxA>((2^7)-1) && minA>=-(2^15) && minA< -(2^7);
x='int16';
elseif maxA<=((2^31)-1) && maxA>((2^15)-1) && minA >=-(2^31) && minA <-(2^15);
x='int32';
elseif maxA<=((2^63)-1) && maxA>((2^31)-1) && minA >=-(2^63) && minA< -(2^31);
x='int64';
elseif maxA<= ((2^8)-1) && minA >= 0;
x = 'uint8';
elseif maxA<= ((2^16)-1) && minA >= 0;
x = 'uint16';
elseif maxA<= ((2^32)-1) && minA >= 0;
x = 'uint32';
elseif maxA<= ((2^64)-1) && minA >= 0;
x = 'uint64';
else
x=NONE;
end
end
but;
Undefined function or variable 'NONE'.
Error in integerize (line 22)
x=NONE;
Steven Lord
Steven Lord 2017 年 11 月 6 日
That's correct, there is no function named NONE in MATLAB or any MathWorks products and no variable by that name in your code. But reread the homework assignment carefully -- in the case where none of the integer types fit, what exactly should be returned? What type should that return value be?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWrite Unit Tests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by