Summary

This document contains practice questions for a MATLAB quiz. The questions cover topics such as matrix manipulation, creating programs to analyze data, and working with functions. It is designed to test the user's understanding of fundamental MATLAB concepts.

Full Transcript

SP25 Name: Quiz 3: MATLAB Questions Answer the following questions related to this matrix called randomMatrix: 1. How would you extract the entry in row 4, column 2? Assign it to variable Q1: Q1 = 2. How would you extract all values in row 3? Assign it to va...

SP25 Name: Quiz 3: MATLAB Questions Answer the following questions related to this matrix called randomMatrix: 1. How would you extract the entry in row 4, column 2? Assign it to variable Q1: Q1 = 2. How would you extract all values in row 3? Assign it to variable Q2: Q2 = 3. What size will the output of the following command be? mean1 = mean(randomMatrix) 4. What size will the output of the following command be? mean2 = mean(mean(randomMatrix)) 5. How would you assign the value of 10 to all rows in a new column 5 in randomMatrix? 1 SP25 Name: Quiz 3: MATLAB 6. Humans can see electromagnetic radiation when the wavelength is within the spectrum of visible light. Create a program to determine if a user- specified wavelength [nanometer, nm] is one of the six spectral colors listed in the following chart. Your program should store the wavelength in a variable named Wavelength, then indicate in which spectral color the given wavelength falls or state if it is not within the visible spectrum. Three example outputs are provided. Color is Red Color is Blue Color not within visible spectrum clear clc % Get wavelength Wavelength = input('\nSpecify a wavelength of electromagnetic radiation in nm: '); 2 F24: ENGR 1102, Section 001 Quiz 4: MATLAB 7. You have been provided the following function to determine your final grade. function letter_grade = assign_grade(grade) % This function takes a numeric grade as input and returns the corresponding letter grade. if grade >= 90 && grade = 80 && grade < 90 letter_grade = 'B'; elseif grade >= 70 && grade < 80 letter_grade = 'C'; elseif grade >= 60 && grade < 70 letter_grade = 'D'; elseif grade >= 0 && grade < 60 letter_grade = 'F'; else letter_grade = 'Invalid grade'; % In case the input grade is out of range (negative or > 100) end end Complete the MATLAB program below to call the function. The output of the function should be stored in a variable called final_grade current_grade = 79.9 %Call Function Here 8. What is the output of the 5 th time the loop below runs? How many total times will this loop run? names = ["Alice", "Bob", "Charlie", "David", "Eva", "Fay", "George", "Hannah", "Isaac", "Jack"]; for i=1:length(names) student_name = names(i) end 3