Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Has to be in MATLAB code please Write a user-defined function that determines th

ID: 3349050 • Letter: H

Question

Has to be in MATLAB code please Write a user-defined function that determines the value that occurs most often in a set of data that is given in a two-dimensional matrix. For the func- tion name and arguments, use [v, q-matrixmode (x). The input argu- ment x is a mxn matrix of any size with numerical values, and the output 26. uments v and q are the values that occur most often and the number of arg times they occur. If there are two, or more, values that occur most often than v is a vector with these values. Do not use the MATLAB built-in func- n mode. Test the function three times. For input create a 5 6 matrix using the following command: x-randi (10,5,6)

Explanation / Answer

Matlab Script:

function [v q] = matrixmode(x)
c= unique(x);
for i=1:length(c)
sum1 = sum(x==c(i));%gives occurrances of each unique element in x in a single column
cnt(i) = sum(sum1);%gives total occurrances
end
idx = 1;
for i=1:length(c)
if cnt(i)==max(cnt)%taking the maximum occurrances elements
v(idx) = c(i);
q(idx) = cnt(i);
idx = idx+1;
end
end
end

Command window output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote