MATLAB: Return the maximum values of each row (as a vector) and the maximum value of the entire matrix

I'm currently writing a function for a vector where it returns the maximum values and the entire maximum value of the entire matrix.
Eg given the vector A = [3 4 5; 5 6 7]
the vector should return [5 7] and entire maximum is 7
this is my code at the moment
function [row_max, matrix_max ] = computeMatrixMax(A)
% inputs: A
% A is a matrix (the size is arbitrary
[rows, columns] = size(A);
row_max = A(1,1);
rows = 1;
columns = 1;
for i = 1:rows
for j = 1: columns
if A(i,j) > row_max
row_max = A(i,j);
end
end
matrix_max = A(1,1);
for p = 2:numel(A)
if A(p) > matrix_max
matrix_max = A(p)
end
end
though it keeps erroring… what am I doing wrong?
EDIT: DON'T WANT TO USE IN-BUILT 'MAX' FUNCTION

Best Answer

You are aware that the answer is simply:
max(A, [], 2) %for the row maximums
max(A(:)) %for the matrix maximum
I assume this is homework, otherwise the above would suffice.
The problem with your code is simply that your row_max is scalar instead of vector and that you never reinitialise it at the beginning of a row.
Most of your variables are very well named. I would encourage you to rename i and j to row and col(umn) respectively and p to element.