What is The Structure in Matlab with Suitable Examples - PowerPoint PPT Presentation

About This Presentation
Title:

What is The Structure in Matlab with Suitable Examples

Description:

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. – PowerPoint PPT presentation

Number of Views:39

less

Transcript and Presenter's Notes

Title: What is The Structure in Matlab with Suitable Examples


1
(No Transcript)
2
matlabassignmenthelp.com
3
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
4
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
names 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.
5
Lets take an example of creating the students
record of a class. The struct can be used
as str_studstruct(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_studstruct(ro
llno,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.
6
matlabassignmenthelp.com
7
matlabassignmenthelp.com
8
STR_STUDSTRUCT(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
9
Corsen-Tallows Builders 2020
10
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 fields values
    in an array structure can not assign to any of
    the variables by using the colon range specifier.
  • Lets 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.
  • BStr_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.

11
MANIPULATING STRUCTURE IN MATLAB
To put the values to certain variable, we can use
the loop construction For i 23,
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.
12
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
13
matlabassignmenthelp.com
14
CONTACT US
Write a Comment
User Comments (0)
About PowerShow.com