Question: 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

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 returnType=integerize(A)

%Define value

returnType = 'none';

%Find maxMatVal

maxMatVal=max(A(:));

%Check Condition

if maxMatVal <= intmax('int8')

%Set Value.

returnType='int8';

%Check Condition

elseif maxMatVal<=intmax('int16')

%Set Value

returnType='int16';

%Check condition.

elseif maxMatVal <= intmax('int32')

%Set Value.

returnType='int32';

%Check Condition.

elseif maxMatVal <= intmax('int64')

%Set Value.

returnType='int64';

%Else

else

%Set Value

returnType='NONE';

%End

end

%End

end

result

Problem 1 (integerize): Feedback: Your function performed correctly for argument(s) 0 Feedback: Your function performed correctly for argument(s) 1 Feedback: Your function performed correctly for argument(s) -1 Feedback: Your function performed correctly for argument(s) -127 Feedback: Your function performed correctly for argument(s) -128 Feedback: Your function performed correctly for argument(s) 126 Feedback: Your function performed correctly for argument(s) 127 Feedback: Your function performed correctly for argument(s) 128 Feedback: Your function made an error for argument(s) [-1 0 23 -129 122]

Your solution is _not_ correct.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!