Question: % % Structures ABCs % % Given Input Variables: % 1 . a _ time - A string of some time % 2 . a

%% Structures ABCs
%% Given Input Variables:
%1. a_time - A string of some time
%2. a_date - Some numerical date
%3. b_time - A string of some time
%4. b_date - Some numerical date
%5. st1- A structure with at least the field 'City'
%6. st2- A structure with at least the fields 'State' and 'TimeZone'
%7. f1- A string of a fieldname in the structure st2
%8. var1- An unknown value
% A. Creating structures manually. Create a structure with two fields:
% 'time' and 'date'. In the first field, 'time', store the value
% contained in the variable "a_time". In the second field, 'date', store
% the value contained in the variable "a_date". Do *NOT* use the
% functions struct() or setfield() for this problem. Your final answer should
% be stored in the variable 'A'.
A =[];
A.time ="a_time"
A.date ="a_date"
% DO NOT DELETE OR MODIFY THIS LINE (AUTOGRADER_CHECK_A)
% B. Creating structures using struct(). Create a structure with two
% fields: 'time' and 'date'. In the first field, 'time', store the value
% contained in the variable A =[];
% the value contained in the variable "b_date". You *MUST* use the
% function struct() for this problem. Your final answer should
% be stored in the variable 'B'.
B = struct(time,"b_time",date,"b_date");
% C. Accessing. What is the value of the field named 'State' in st2? You
% may *NOT* use getfield() for this problem. Your final answer should
% be stored in the variable 'C'.
C = st2.State;
% D. Accessing indirectly. The variable f1 will contain a string
% representing a fieldname. What is the value of the field f1 in the
% structure st2? You may *NOT* use getfield() for this problem. Your
% final answer should be stored in the variable 'D'.
D =[];
% E. fieldnames(). Use the function fieldnames() to create a cell array
% containing a list of all the fields from st2. Your final answer should
% be stored in the variable 'E'.
E =[];
% F. rmfield(). Use the function rmfield() to create a structure equal to
% st2 with the field named 'TimeZone' removed. The original structure st2
% should not be changed. Your final answer should be stored in the variable 'A'.
F =[];
% G. After running the following line of code, will the field named 'City'
% exist within st1? If yes, the answer should yield the logical true,
% and if no, the answer should yield the logical value false. (I)
%>> rmfield(st1,'City')
% Important Note: This is not the same as st1= rmfield(st1,'City')
G =[];
% H. isstruct(). Is the value of var1 a structure? You answer should be
% either the logical true if var1 is a structure and false otherwise.
H =[];
% I. isfield(). Does st1 have a field named 'Major'? You answer should be
% either the logical value true if st1 does have a field named 'Major'
% and false otherwise.
I =[];

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!