MATLAB code please 2\" (60%) In the same parade there was a marching band consis
ID: 3738844 • Letter: M
Question
MATLAB code please
2" (60%) In the same parade there was a marching band consisted of males and females. The band was arranged in n rows and m columns. The gender distribution of the band members was random. The members used five musical instruments: drums, trumpets, piccolos, clarinets and trombones which were also distributed randomly. Write a program that will perform the following: a. (10%) Accept the values n and m and define appropriate size arrays to describe the b. (10%) Fill the first arrays with a code corresponding to the gender and the second c. (1000) Determin d. (15%) Determine how many instruments of each kind in the band and print out the e. ( gender and the instrument of each member in the band array with a code corresponding to the instruments the member plays. Print the arrays the results. results. e how many males and how many females in the band and print out 10%) Determine how many males in the row and print out the results. (10%) Determine how females in first column and print out the results. f. (10%) Use the same array of problem 2 and determine how many males are playing drums and print out the results. 3,Explanation / Answer
a) m = input(prompt)
n = input(prompt)
A = strings(m,n)
B = strings(m,n)
b) M="Male"
F= "Female"
#For the Gender matrix
for i = 1:m
for j = 1:n
A(i,j) = round(rand);
end
end
d = drums;
tru = trumpets;
p = piccolos;
c = clarinets;
tro = trombones;
#Similarly for the Instruments matrix
for i = 1:m
for j = 1:n
A(i,j) = round(randi(5));
end
end
#Sorry for the irregular indendations
#Now the matrices are available.
c) Though we can count while assigning the values. We shall run the for loop again.
Males=0,Females=0;
for i = 1:m
for j = 1:n
end
end
disp(Males,Females)
d) Same as above we compare with each instrument and count the number of people holding it.
drum=0;
trump=0;
pian=0;
clari=0;
trombo=0;
for i = 1:m
for j = 1:n
if A(i,j) == d
end
end
disp(drum,trump,pian,clari,trombo)
e) Now, go row wise and iterate again we would get males for each row.
Males=0;
for i = 1:m
for j = 1:n
end
disp(Males);
Males=0;
end
f) Just iterate through columns now
Females=0;
for j = 1:m
for i = 1:n
end
disp(Females);
Females=0;
end
Hope this helps.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.