| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
The MATLAB language enables you to use both general-purpose and specialized arrays. For example, numeric multidimensional arrays and structures provide general-purpose data storage. You typically extract data from the array and perform operations (e.g., mathematical analysis) on this data, and then store the data back in general-purpose variables.
When using a specialized object, you typically pass the object's data to a function that creates the object. Once you have created the object, you use specially defined functions to operate on the data. These functions are unique to the object and are designed specifically for the type and structure of the data contained by the object.
A commonly used general-purpose data structure is a structure array. For example, these statements create a MATLAB struct (a MATLAB structure array):
s.Data = rand(10,1); s.Time = .01:.01:.1; s.Name = 'Data1'; s.Units = 'seconds';
The structure s contains two arrays of numbers. However, s is a generic type in the sense that MATLAB does not define special functions to operate on the data in this particular structure. For example, while s contains two fields, Data and Time, that would be useful to plot, you cannot pass s to the plot function:
plot(s)
??? Error using ==> plot
Not enough input arguments.While s certainly has enough information to create a plot of Data versus Time, plot cannot access this data because structures like s can contain any values in its fields and the fields can have any name. Just because one field is named Data does not force you to assign data to that field.
To plot the data in s, you would have to extract the data from the fields, pass them as numeric arrays in the desired order to the plot function, add a title, labels, and so on:
plot(s.Time,s.Data) title(['Time Series Plot: ' s.Name]) xlabel(['Time (' s.Units ')']) ylabel(s.Name)
You could create a function to perform these steps for you. Other programs using the structure s would need to create their own functions or access the one you created.
Compare the structure array above to an object that has been specifically designed to contain and manipulate time series data. For example, the following statement creates a MATLAB timeseries object. It is initialized to store the same data as the structure s above:
tsobj = timeseries(rand(10,1),.01:.01:.1,'Name','Data1');
The function that creates the object tsobj, accepts sample data, sample times, a property name/property value pair (Name/Data1), and uses a default value of Units (which is seconds).
The designer of this object created a special version of the plot function that works directly with this object. For example:
plot(tsobj)

Notice how the object's plot function creates a graph that is plotted and labeled with the data from the tsobj object. As a user of this object, you do not need write your own code to produce this graph. The class design specifies the standard way to present graphs of timeseries data and all clients of this object use the same code for plotting.
See Time Series Objects for more on using MATLAB timeseries objects.
![]() | MATLAB Objects | Key Object Concepts | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |