Sale!

ECE210 MATLAB Assignment 5 solution

$30.00 $25.50

Category:

Description

5/5 - (5 votes)

In this homework, we will go through a few advanced data structures in MATLAB, such as structures, classes, chars, as well as file input and output in MATLAB. You would be importing in the
fisheriris dataset and encapsulating it in classes. After obtaining all the data, you would be required
to write some funtions for the class you just created. It is advised that after each stage, you save
your variables, say, all your kickstarter instances, into a .mat file such that you would not need
recreate all the classes again. Please send the homework to so@cooper.edu by February 28th, 2018
. Also note that some operations will require you to do some research (such as trimming trailing
white spaces and looking up the fisheriris dataset)
(a) Load in the fisheriris dataset with the command load fisheriris . You should obtain a 150 × 4
matrix called meas and 150 × 1 cell array called species in your workspace. To find out what
each column in the meas matrix stand for, you need to go online and do some research. It is a
very popular dataset and the meaning of each column should not be hard to find.
(b) Create a class called Flower. In your Flower class, you should have the following properties
– petalWidth (double), petalLength(double), sepalWidth(double), sepalLength(double) and
species(char). The ith species corresponds to the ith row of information in meas. Note that
you do not need to specify the data type of the properties when you are declaring a class the
following properties are just here to impress on you what type of properties you would be
expecting.
(c) Create a constructor for Flower that will take in four doubles and one char array for the 4
measurements and class respectively.
(d) Now, import the entries from meas and species the into MATLAB and store it in a cell array
of Flower instances. You can either use a for loop to import the entries, or use a more elegant
way to make all entries in one line (this would require some research on object formation in
matlab). Either way will be fine for this task. However, note that the name of the species are
stored as cell arrays, make sure to extract from the cell as a char and remove trailing white
spaces before storing them in the Flower instances.
(e) Create a method called getSLength for the Flowers object, which will return the sepal length
of the object. Test it and make sure it works.
(f) Create another method called report for the Flowers object, which will print out a statement
on the command window and report the details about the Flowers object. This function does
not need to return anything. If the flower is 5.1cm in sepal length, 3.5cm in sepal width, 1.4cm
in petal length and 0.2cm in petalWidth, and the species is setosa, print out the following
statement:
”The length and width of its sepal are 5.1cm and 3.5cm respectively, while that of its petal are
1.4cm and 0.2cm respectively. It belongs to the setosa class.”
1