ABCs_structure_arrays - have not explicity been assigned a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 function [A B C D] = ABCs_structure_arrays(str1, str2, str3, sa1) % PROBLEM 2. The ABCs of Structure Arrays % % This is a multi-part problem. Do each of the parts below. % % DO NOT CHANGE THE FUNCTION HEADER (the first line of code) % % a) Creating structure arrays manually. str1, str2, and str3 are three % similar structures (similar means they have the same fields in the same % order). Create a structure array of length three containing str1, str2, % and str3 in that order. % % Store your answer in the variable A. Write your code here: A = [str1 str2 str3] % b) Adding elements to a structure array. sa1 is a structure array. Two % of its fields are 'name' and 'class'. Add another element to the end by % setting the value of the 'name' field to 'George'. % % Store your answer in the variable B. Write your code here: sa1(end).name = 'George' B = sa1(end).name % c) What is the default value assigned to fields in a structure array that
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % have not explicity been assigned a value, but have been created % automatically because of adding fields or because of extending the length % of the structure array? % % Store your answer in the variable C. Write your code here: C = % d) Create a structure array of length three with the fields: 'truck', % 'model', and 'color'. The field values for each of the three elements % should be as follows: % % 1) truck: 'Dodge' model: 'Ram' color: 'red' % 2) truck: 'Chevy' model: 'Silverado' color: 'red' % 3) truck: 'Ford' model: 'F150' color: 'red' % % Note that you *MUST* use struct() for this problem. % % Store your answer in the variable D. Write your code here: D(1) = struct('truck', 'Dodge', 'model', 'Ram','color','red') D(2) = struct('truck','Chevy','model','Silverado','color','red') D(3) = struct('truck','Ford','model','F150','color','red')...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online