Function Name: myStruct Inputs: 1. (cell) A 1xN cell array containing fieldnames
ID: 664975 • Letter: F
Question
Function Name: myStruct
Inputs:
1. (cell) A 1xN cell array containing fieldnames and data
Outputs:
1. (struct) The contents of the input cell array in the form of a structure
Function Description:
Write a Matlab function that creates a structure from a given cell array. The cell array will be formatted in the following way:
inCellArr = {<field1_name>, {cell_array_of_field1_contents}, <field2_name>, {cell_array_of_field2_contents}, <field3_name>, {cell_array_of_field3_contents}, <field4_name>, ...} %etc.
Take the cell array and create a structure array, where the fieldnames are given by the strings in the odd-numbered indices and the field contents are given by the field content cell arrays in the even-numbered indices. Each element in the field content cells should be stored individually in the corresponding index of the structure (i.e. if the field content cell arrays are 1xM, then the output structure should be 1xM). The field content cell arrays will all be the same size, with the singular exception of a 1x1 cell. In this case, that single element should be assigned to that field name for every index of the structure (i.e. if your structure is 1xM, then all M elements for this field will be the same piece of data, which is the contents of the singular cell).
Notes:
The input cell array will always have an even length.
You may NOT use the struct() function. The premise of this problem is for you to thoroughly learn how it works by coding it yourself. Any submission that uses the struct() function will receive 0 credit.
You may NOT use the cell2struct() function.
You must always assign the contents of a 1x1 cell array into each index of the output structure, not the 1x1 cell itself.
Explanation / Answer
Please post the matlab questions under the electriacal engineering category.Do not post the matlab questions under the computer science category.
Thanks.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.