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

give comments in front of each line explaining each code. 25. Write a user-defin

ID: 3737006 • Letter: G

Question

give comments in front of each line explaining each code.
25. Write a user-defined function that determines the mode of a set of data (the value in the set that occurs most often). For the function name and arguments, use m-mostfrq(x). The input to the function is a vector x of any length with values, and the output m is a two-element vector in which the first ele- ment is the value in x that occurs most often, and the second element is the mode. If there are two, or more, values for the mode the output is the message: There are more than one value for the mode." Do not use the MATLAB built-in function mode. Test the function three times. For input create a 20- element vector using the following command: x-randi ( 1 0 , 1 , 2

Explanation / Answer

ScreenShot

---------------------------------------------------------------------------------------------------------------------------------------

Code:-

% random vector generation from 1-10(20 numbers)
x=randi(10,1,20)
%Function definition
function m=mostfreq(x)
% find the count of each element in the vector a=count and b=element
[a,b]=hist(x,unique(x));
%find max count and corresponding value in x
[t,i]=max(a);
% result
m=[b(i),t];
end
%function call
mode=mostfreq(x)

----------------------------------------------------------------------

Note:-

I am using Octave.

Clarification,please let me know.