Expert in coding needed! matlab programming required The statistic term, \"mode\
ID: 3681427 • Letter: E
Question
Expert in coding needed! matlab programming required
The statistic term, "mode", is the value that appears most often in a set of data. For example, the mode of this set of data, 2, 8, 5, 3, 7, 3, 4, 5, 3, is 3. A set of data can also be bi-modal or multi-model is two or more values occur for the same number of times. For example, the data set, 2, 5, 1, 4, 5, 2, 3, has two modes, 2 and 5. Write a script that generates a 1by20 vector containing random integers in the range [1-15], and then find the mode (or modes). Use the array traversing skills; do not use built-in functions such as sort () , max () , min () or mode ().Explanation / Answer
findmodes.m
function [modes] = findmodes()
clc;
a = randi(15,1,20)
b = unique(a);
count = zeros(1,length(b));
for i = 1:length(b)
count(i) = sum(a==b(i));
end
maxcount = count(1);
for i = 1:length(b)
if count(i) > maxcount
maxcount = count(i);
end
end
temp_modes = (count == maxcount).*b;
modes = zeros;
num = 1;
for i = 1:length(temp_modes)
if temp_modes(i) > 0
modes(num) = temp_modes(i);
num = num+1;
end
end
modes
Output :
a =
Columns 1 through 15
11 6 4 9 14 7 2 7 5 7 13 7 6 6 3
Columns 16 through 20
4 2 7 4 5
modes =
7
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.