Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solve with MatLab Question 3 (6 points): Purpose: Writing functions in MatLab, data processing Degree of Difficulty: Tricky Just like in Python, you can define
Solve with MatLab
Question 3 (6 points): Purpose: Writing functions in MatLab, data processing Degree of Difficulty: Tricky Just like in Python, you can define functions in MatLab. One property of MatLab functions is that they can return more than 1 value! Like in the last question, there's a file called pizzahut.cav. It contains 1 row per Pizza Hut location. The file has the following columns Latitude, Longitude,Location, Address and Phone Number Place pizzahut.cBv in the same folder as your a9q.file. You can import pizzahut.csv with the fol- lowing code: pizzahut readtable( , pizzahut .csv, , , ReadVariableNames , , false) ; You now have a ta- ble called pizzahut. Tables are a bit different in MatLab. They can have different types of values in their columns, instead of an ordinary matrix whose values must all be of the same time To access the value inside an entry of our table, use(Icurly brackets instead of I1 brackets. Ex: pizzahut(1,1 gives-149.9147 Our table contains different data types in each column. You may need to check the data type of the cell to determine how to check for NaN. Ex: inumeric(curront aluo& ianan (current value) would check whatever current value is for NaN if it's a number column Sometimes the data you receive is incomplete, or has invalid entries. Some invalid entries are denoted as NaN, which means 'Not a Number. Write the following function: function altered data, NaN found clean up.data (data, NaN.valse) To declare a function in MatLab, you'll need to create a new function file called clean_up data.'. You will then place your function declaration: function altered data, NaN found clean_up.data data NaN_value) inside this new m file. You will be able to call this function from your a9q3. Like you would any function in Python. This clean up data function needs to: Count the number of NaN entries the data has, and return it as the variable NaN found . Remove each row that contains a NaN' value e Return the altered data as the variable new data. Your file will need to read in pizzahut.cev, then pass that data to your clean updata function. After you've passed the variable pizzahut to your clean up data function, print out the returned number of NaN's that were found. Your output should look something like: Nuber of NaNa found:10 Hint: There are many ways to remove NaN values. Use your googlefu, and do some research! What to Hand In .A document called a9q3.m containing your code that calls the function clean up_data as described above .A document called clean, up data.m containing your function described as above Question 3 (6 points): Purpose: Writing functions in MatLab, data processing Degree of Difficulty: Tricky Just like in Python, you can define functions in MatLab. One property of MatLab functions is that they can return more than 1 value! Like in the last question, there's a file called pizzahut.cav. It contains 1 row per Pizza Hut location. The file has the following columns Latitude, Longitude,Location, Address and Phone Number Place pizzahut.cBv in the same folder as your a9q.file. You can import pizzahut.csv with the fol- lowing code: pizzahut readtable( , pizzahut .csv, , , ReadVariableNames , , false) ; You now have a ta- ble called pizzahut. Tables are a bit different in MatLab. They can have different types of values in their columns, instead of an ordinary matrix whose values must all be of the same time To access the value inside an entry of our table, use(Icurly brackets instead of I1 brackets. Ex: pizzahut(1,1 gives-149.9147 Our table contains different data types in each column. You may need to check the data type of the cell to determine how to check for NaN. Ex: inumeric(curront aluo& ianan (current value) would check whatever current value is for NaN if it's a number column Sometimes the data you receive is incomplete, or has invalid entries. Some invalid entries are denoted as NaN, which means 'Not a Number. Write the following function: function altered data, NaN found clean up.data (data, NaN.valse) To declare a function in MatLab, you'll need to create a new function file called clean_up data.'. You will then place your function declaration: function altered data, NaN found clean_up.data data NaN_value) inside this new m file. You will be able to call this function from your a9q3. Like you would any function in Python. This clean up data function needs to: Count the number of NaN entries the data has, and return it as the variable NaN found . Remove each row that contains a NaN' value e Return the altered data as the variable new data. Your file will need to read in pizzahut.cev, then pass that data to your clean updata function. After you've passed the variable pizzahut to your clean up data function, print out the returned number of NaN's that were found. Your output should look something like: Nuber of NaNa found:10 Hint: There are many ways to remove NaN values. Use your googlefu, and do some research! What to Hand In .A document called a9q3.m containing your code that calls the function clean up_data as described above .A document called clean, up data.m containing your function described as aboveStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started