8.9: Chapter Exercises
- Page ID
- 136689
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\dsum}{\displaystyle\sum\limits} \)
\( \newcommand{\dint}{\displaystyle\int\limits} \)
\( \newcommand{\dlim}{\displaystyle\lim\limits} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\(\newcommand{\longvect}{\overrightarrow}\)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\ket}[1]{\left| #1 \right>}\)
\(\newcommand{\bra}[1]{\left< #1 \right|}\)
\(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
\(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
\(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
\(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
\(\newcommand{\expect}[1]{\langle #1 \rangle}\)
\(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)
Exercise 1:
Create a cell array named mixedData that stores your first name, your favorite number, a vector of three numbers, and a logical value. Display each item using curly brace indexing.
Exercise 2:
Create a 2-by-3 cell array. Store text in the first row and numbers in the second row. The in one line of code, extract the value in row 2, column 3.
Exercise 3:
Create a cell array named phrases that stores at least five motivational phrases. Use randi to randomly display one phrase.
Exercise 4:
Create a structure named book with fields Title, Author, Year, and Pages. Display the Title field.
Exercise 5:
Create a structure named sensor with fields ID, Location, Units, and Reading. Change the Reading field to a new value.
Exercise 6:
Create a cell array named cars that stores information about three cars. Each row should contain make, model, year, and mileage. Extract the mileage column.
Exercise 7:
Create a script named studentInfo that prompts a student for first name, last name, student ID number, and GPA. Store the information in a structure and print a sentence summarizing the information.
Exercise 8:
Create a structure array named students with three students. Each student should have fields FirstName, LastName, ID, and GPA. Create a vector containing all GPAs.
Exercise 9:
Create a structure array named parts with fields item_no, cost, price, and code. Calculate the profit for each part and store it in a new field named profit.
Exercise 10:
Write a script that converts a cell array of bood donor information into a structure array with fields Last, First, Type, Rh, Systolic, and Diastolic.
Exercise 11:
Create a table named studentsTable with variables FirstName, LastName, ID, and GPA for at least four students. Extract the GPA variable and calculate the average GPA.
Exercise 12:
Create a table of car information with variables Make, Model, Year, and Mileage. Use logical indexing to display only the cars with mileage less than 50000.
Exercise 13:
Convert a small cell array of donor information into a table with meaningful variable names. Then use dot notation to extract one column.
Exercise 14:
Write a function named cellParse that takes a cell array as input. Each element may be a string, character vector, numeric vector, or logical value. The function should return the number of strings, character vectors, numeric arrays, and logical values in the cell array.
Exercise 15:
Write a script named makeClothes that creates a structure array of clothing items. Then write a local function named rateClothes that adds Rating and Quality fields to each item using the rating equation in this chapter.
Exercise 16:
Write a function named usedCar that takes a car structure with fields Make, Year, Cost, Miles, and Accidents. Adjust the Cost field according to the rules in the used car example.
Exercise 17:
Create a small inventory system using a structure array. Each item should have fields Name, Quantity, UnitCost, and Category. Write code that calculates the total value of the inventory.


