MATLAB I am in need of help with these questions 1.) Given a 50 element array ca
ID: 3693943 • Letter: M
Question
MATLAB
I am in need of help with these questions
1.) Given a 50 element array called fifty and random numbers between 1 and 50, count the occurrences of each number by incrementing the corresponding element (i.e., if a 3 is generated, then element 3 is incremented by 1). You should use a for-loop to generate 235 random numbers. Output the results of the fifty array (you may not use %g):
%for-loop to generate 235 random numbers
num = randi(50); %generates one random number from 1 to 50
%output fifty array
2.) Traverse through two integer arrays – array1 & array2, outputting each elements’ value and whether or not they are equal.
3.) Determine the average score in a scores array. Then, traverse scores again and determine how many scores are above the average and how many below – output both these number.
4.) An array letters contains elements made up of only single lowercase letters. Determine the number of times vowels occur and the number of times consonants occur.
5.) An array grades contains percentages of test grades.
Populate a corresponding letterGrades array with the letter grade:
grades = [89, 80, 69, 99, 75, . . . , 69, 90 ];
letterGrades = [ ];
90-100: A
80-89 : B
70 - 79: C
60 - 69: D
< 59 : F
6.) You want to the automate grading of the multiple choice part of an exam from the open file test3_Answers.txt, using the file handle inFile. Populate an array called test3Answers that contains the correct answers to the test questions. You may assume one answer on each line of the input file.
Next, determine the number of questions student1 has gotten correct, and whether or not he/she passed the exam. A passing grade is any score 21 or greater (60%).
student1 = {‘A’, ‘B’, ‘D’, ‘D’, ‘D’, ‘C’, ‘C’, ‘A’, ‘B’, ‘B’, ‘C’, ‘A’, . . ., ‘A’, ‘A’, ‘D’};
index = 1; %index used to populate test3Answers
test3Answers = [ ];
correct = 0;
while ~feof(inFile)
>
%populate test3Answers array
90-100: A
80-89 : B
70 - 79: C
60 - 69: D
< 59 : F
Explanation / Answer
a)
a:= array(1..50, [1 $ i = 1..50]
for i=1 to 235
k=randi(50)
a(k):=a(k)+1
end
display(a)
b)
for i=1 to array1.length
display("element " + i )
display (array1[i])
display (array2[i])
if (array1[i]=array2[i]) then
display("Both elements of arrays are equal")
else
display("Both elements of arrays are not equal")
end
end
c)
avg=0
for i =1 to array.length
avg:=avg+array[i]
end
avg:=avg/array.length
count = 0
for i = 1 to array.length
if array[i]>avg then
count:=count+1
end
end
Display(avg)
Display(count)
e) for i = 1 to grades.length
if grades[i] > 90 then
letterGrades[i]='A'
else if grades[i] > 80 then
letterGrades[i]='B'
else if grades[i] > 70 then
letterGrades[i]='C'
else if grades[i] > 60 then
letterGrades[i]='D'
else
letterGrades[i]='F'
end
end
Display(letterGrades)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.