140 likes | 152 Views
Don't you know what is the structure in MATLAB? If yes, then here is the best ever presentation on what is structure in matlab. Watch this presentation till the end to know everything about structure in matlab.
E N D
MATLAB ASSIGNMENT HELP WHAT IS THE STRUCTURE IN MATLAB By matlabassignmenthelp.com
OUTLINE OF TOPICS WHAT WE'LL DISCUSS Overview Syntax of structure in MatLabE xamples of structure in MatLab Structure with no field To get the specific values of the fields in the structure in MatLab Adding a new field to the structure field Scalar structure containing the fields Structure array in MatLab Manipulating structure in MatLab Conclusion matlabassignmenthelp.com
OVERVIEW A structure in MatLab is a data type that is used to group the related data types using the data containers known as fields. Each field has different data types and a single field must have the same kind of data. The notation used to represent the structure in MatLab is “struct” which can be a single field, no field, or multiple fields. It could be multi-dimensional or one dimensional. The value in the structure can be added with the help of fieldName and structure name that is linked with the dot operator as structName.fieldName. The character value can be added using ‘’ and numerical values can add as it is. matlabassignmenthelp.com
SYNTAX OF STRUCTURE IN MATLAB STR_NAME = STRUCT(‘FIELDNAME1’, VALUE1, ‘FIELDNAME2’, VALUE2, …) This syntax method is used for creating a structure array with particular values and fields. Here, the value type arrays are value1, value2… with the same size of the cell. The name of the fields for a structure field should be initiated with an alphabet as it is case-sensitive. The remaining portion of the field name should have numbers, alphabets, and special characters. To find the maximum field name’s length, one can use command “namelengthmax”. There are several ways to create a structure, such as: struct([]): It is used to create no field or empty structure. Str_name = struct(‘fieldname1’, {}, ‘fieldname2’, {}….): It is used to create an empty structure with fields named as fieldname1, fieldname2,…. struct(o): It is used to transform the object ‘o’ to its equivalent structure.
Let’s take an example of creating the student’s record of a class. The struct can be used as: str_stud=struct(‘rollno’,[1 2 3], ‘subject’, char(‘physics’, ‘chemistry’, ‘maths’)) The above example has the str_stud as a structure name that has field names ‘rollno’ and ‘subjects’ that all have different values. Examples of structure in MatLab We have listed some of the examples that are used in MatLab to structure various fields: Structure with fields str_stud=struct(‘rollno’,[5 6 7],’subjects’,char(‘chem’ , ‘phy’,bio)) The output of the structure in MatLab program will be as follows: str_stud= Scalar structure containing the fields: Rollno = 5 6 7 Subjects = Chem Phy maths Structure with no field Str_stud =struct The output will be as follows Str_stud = Scalar structure containing the fields: As it does not have any field; therefore, it will represent null value to the field.
STR_STUD=STRUCT(‘ROLLNO’,[5 6 7],’SUBJECTS’,CHAR(‘CHEM’, ‘PHY’,’BIO’)) TO GET THE SPECIFIC VALUES OF THE FIELDS IN THE STRUCTURE IN MATLAB: Str_stud.rollno The output of this program will be: str_stud= Scalar structure containing the fields: roll no= 5 6 7 subjects= Chem Phy Bio ans= 5 6 7 matlabassignmenthelp.com
STR_STUD=STRUCT(‘ROLLNO’,[5 6 7],’SUBJECTS’,CHAR(‘CHEM’, ‘PHY’,’BIO’)) ADDING A NEW FIELD TO THE STRUCTURE FIELD str_stud.rollno(4)=8 The output of the structure in MatLab program will be shown as: str_stud= Scalar structure containing the fields: rollno= 5 6 7 subjects= Chem Phy Bio str_stud= Scalar structure containing the fields rollno= 5 6 7 8 subjects= Chem Phy Bio matlabassignmenthelp.com
STRUCTURE ARRAY IN MATLAB STR_STUD=[STRUCT(‘ROLLNO’,[5 6 7], ‘SUBJECTS’,CHAR(‘CHEM’ ,’PHY’,’MATHS’)); STRUCT(‘ROLLNO’,[8 9 10], ‘SUBJECTS’,CHAR(‘CHEM’,’PHY’, ‘BIO’)); STRUCT(‘ROLLNO’,[11 12 13], ‘SUBJECTS’,CHAR(‘COMP’ ,’MATHS’, ’SST’))]; STR_STUD THE OUTPUT OF THIS 3X1 STRUCTURE ARRAY WILL BE REPRESENTED AS: STR_STUD= 3X1 STRUCT ARRAY CONTAINING THE FIELDS: ROLLNO SUBJECTS matlabassignmenthelp.com
WIDER SPACES MAJOR CHANGES Presentations are communication tools that can be used as demonstrations, lectures, speeches, reports, and more. Most of the time, they’re presented before an audience. SAFETY FEATURES Presentations are communication tools that can be used as demonstrations, lectures, speeches, reports, and more. Most of the time, they’re presented before an audience. IMPROVED STRUCTURES Presentations are communication tools that can be used as demonstrations, lectures, speeches, reports, and more. Most of the time, they’re presented before an audience. Corsen-Tallows Builders 2020
MANIPULATING STRUCTURE IN MATLAB • It is similar to array manipulation, in that using the components of the structure in MatLab changes the values of a specific field. The difference in this is that the field’s values in an array structure can not assign to any of the variables by using the colon range specifier. • Let’s take in an example of it • The non-valid and valid operations for str_stud in 3X1 structure array are: • Str_stud(1).subjects(:) offers the components of subjects from Str_stud(1), similar as Str_stud(1).subjects. • Str_stud(1).subjects(2) can be valid and offers the second component of subjects from the initial record of str_stud. • B=Str_stud(:).subjects is invalid, and it can not be assigned subjects from the records to B, though this command Str_stud.subjects or Str_stud(:).subjects or shows subjects from all records.
MANIPULATING STRUCTURE IN MATLAB To put the values to certain variable, we can use the loop construction: For i = 2:3, all_subjects(i,:)= str_stud(i).subjects; end. The values can not directly assign by using the colon as a field value from several records can be considered as individual entities. The field contents are used for different sizes. The loops are used for assignment, in the above example, str_stud(3).subjects have 3 entries; therefore, the assignment will show an error and this proves that indices are used for accessing the data. You can use a structure within the structure in MatLab with the level of indexing. It can be a little tough or confusing, and it needs some extra efforts for nested structures.
CONCLUSION This blog has all the relevant information about the structure in MatLab. We have specified all the structure types with their examples. This will help you to understand how to use the structure to provide specific values to certain data fields. The MatLab is using the struct function to keep the records of the specific data type. That might be one dimensional or multidimensional that is known as a structure array in MatLab. matlabassignmenthelp.com
Follow us on Social Media FACEBOOK INSTAGRAM TWITTER @matlabassignmenthelp @matlabassignme5 @matlabassignmenthelp1 matlabassignmenthelp.com
WEB ADDRESS EMAIL CONTACT US info@matlabassignmenthelp.com matlabassignmenthelp.com