MATLAB: Write a function called minimax that takes M, a matrix input argument and returns mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. As a second output argument called mmm

minimax

Write a function called minimax that takes M, a matrix input argument and returns mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. As a second output argument called mmm, it provides the difference between the maximum and minimum element in the entire matrix. See the code below for an example:
>> A = randi(100,3,4) %EXAMPLE
A =
66 94 75 18
4 68 40 71
85 76 66 4
>> [x, y] = minimax(A)
x =
76 67 81
y =
90
%end example
%calling code: [mmr, mmm] = minimax([1:4;5:8;9:12])
My answer to this:
function [mmr,mmm] = minimax(M)
mmr = abs(max(M.')-min(M.'));
mmm = max(max(M)) - min(min(M));
This is shortest code I could write. What do you guys think of this?

Best Answer

function [mmr,mmm] = minimax(M)
a=max(M');
b=min(M');
mmr=a-b;
c=max(a);
d=min(b);
mmm=c-d;
end
% This is what i came up with. Please give a upthumb if it works.