Abstract
Data structures are variables that store more than one value. There are many different kinds of data structures. We have already been working with one kind, arrays (e.g., vectors and matrices). We use vectors and matrices when we want to be able to loop through them (or, essentially, have this done for us using vectorized code). A cell array is a kind of data structure that stores values of different types. Cell arrays can be vectors or matrices; the different values are referred to as the elements of the array. One very common use of a cell array is to store strings of different lengths. Structures are data structures that group together values that are logically related, but are not the same thing and not necessarily the same type. The different values are stored in separate fields of the structure. One use of structures is to set up a database of information. In many programming languages and database programs the terminology is that within a database file there would be one record of information; each separate piece of information would be called a field of the record. In the MATLAB ® software these records are called structs. Both cell arrays and structures can be used to store values that are different types in a single variable. The main difference between them is that cell arrays are indexed, and can therefore be used with loops or vectorized code. Structures, however, are not indexed; the values are referenced using the names of the fields, which can be more mnemonic than indexing.
Talk to us
Join us for a 30 min session where you can share your feedback and ask us any queries you have
More From: Matlab® A Practical Introduction to Programming and Problem Solving
Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.