3. write a user-defined MATLAB function that finds the largest element of a matr
ID: 2082282 • Letter: 3
Question
3. write a user-defined MATLAB function that finds the largest element of a matrix. For the function name and a use [Emrc] matrixmax(A), where A is any size matrix. The output argument Em is the value of the largest element, and rc is a two- element vector with the address of the largest element (row and column numbers). If there are two, or more, elements that have the maximum value, the output argument rc is a two-column matrix where the rows list the addresses of the elements. Test the function three times. For input create a 4x6 matrix using the following command: x randi I-20100] 4.60. Answer (two examples): x randi (I-20100),4,6) 38 41 57 22 55 36 32 41 25 93 51 7 34 78 78 85 5 82 17 76 44 46 16 3 [Em,rol matrixmax(x)Explanation / Answer
MATLAB Code
clear all
close all
clc
x=randi([-20 100],4,6)
em=max(x(:));
i=1;
j=1;
k=1;
for i=1:4
for j=1:6
if x(i,j)==em
tableA(k,:)=[i j];
k=k+1;
end
j=j+1;
end
i=i+1;
end
em
re=tableA()
sample output
x =
82 50 -20 43 40 69
47 78 84 38 89 50
92 86 54 76 49 9
64 99 99 7 82 60
em =
99
re =
4 2
4 3
>>
x =
-10 87 92 84 46 23
55 98 50 38 56 -15
59 73 -18 82 -17 39
68 50 -6 5 54 3
em =
98
re =
2 2
>>
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.