In: Computer Science
MATLAB:
Write a function called problem2 that takes an at most two-dimensional matrix A as its sole input. The function uses a while-loop to return the largest element of A. You are not allowed to use the built-in max function and you are also not allowed to use for-loops.
problem2.m
-----------------------------------------------------------------------------------------------------------------------------------
function [max] = problem2(arr)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%row have no of row of entered matrix
%col have no of column of entered matrix
[row,col]=size(arr);
i=1; % i for row index
% max contain 1st element of 2d matrix
max=arr(1,1);
while i<=row
j=1; % j for column index
while j<=col
if (arr(i,j)>max)
max=arr(i,j);
end
j=j+1; % increment for column
end
i=i+1; % incremnet for row
end
end
-----------------------------------------------------------------------------------------------------------------------------------------------------
Output of 2 sample input