hi I need help with this Write a function that receives an a
hi! I need help with this:
Write a function that receives an array of any size and maximum and minimum return of all numbers in the matrix. Schedule your function using loops, DO NOT use the predefined functions allowed Matlab: min, max, sort, sortRows.
Solution
Code:
findMinMax.m file
function [min, max] = findMinMax(a)
len = length(a);
min = a(1);
max = a(len);
for i=1:len
if(gt(min,a(i)))
min = a(i);
end
if(le(max,a(i)))
max = a(i);
end
end
end
test.m file
a = [7, 2, 4, 8, 6, 1, 9, 10, 3];
[min, max] = findMinMax(a);
min, max
Output:
min = 1
max = 10
