In: Computer Science
MATLAB: Write a function called max_number that takes an at most two-dimensional matrix A as its sole input. The function returns the largest element of A. You are not allowed to use the built-in max function.
Hey just to make it interesting I will only show you the function of 1-D matrix to determine max element.
It goes like this:
now to work on the 2D array you apply various methods:
1st:
divide the elements of the 2D array into number_of_rows simple 1D arrays.
now you have 3 1d arrays and you apply the max function on each of them to get the max from each as:
maxf(A1)=5
maxf(A2)=6
maxf(A3)=9
create a new 1D matrix with elements maxf(A1),maxf(A2),maxf(A3) and apply maxf on that matrix.
you will get the output as 9.
2nd method:
In this case you will have to write a seperate maxf function for 2D array as the one with 1D array won't work.
Steps:
Personally I'll reccomend the 1st Method.
Try it..