MATLAB Examples

Create handles to local functions. If a function returns handles to local functions, you can call the local functions outside of the main function. This approach allows you to have multiple,

Typically, you can import tables using the readtable function. However, sometimes importing tabular data requires additional control over the import process. For example, you might want

These examples show several ways to pass data from a cell array to a MATLAB® function that does not recognize cell arrays as inputs.

Index and search using categorical arrays. You can access data using categorical arrays stored within a table in a similar manner.

Use relational operations with a categorical array.

You can search for text in character arrays and string arrays, and replace substrings with new text. String arrays, and new functions to search for and replace text, were introduced in

Create a scatter plot with datetime or duration inputs using the scatter or scatter3 functions. For example, create a scatter plot with dates along the x -axis.

Create a table from a subset of a larger table.

Two ways to extract date and time components from existing datetime arrays: accessing the array properties or calling a function. Then, the example shows how to modify the date and time

Create a table from workspace variables, work with table data, and write tables to files for later use. table is a data type for collecting heterogeneous data and metadata properties such as

Add, delete, and rearrange column-oriented variables in a table. You can add, move, and delete table variables using the addvars , movevars , and removevars functions. As alternatives, you

Use the dateshift function to generate sequences of dates and time where each instance obeys a rule relating to a calendar unit or a unit of time. For instance, each datetime must occur at the

You can combine timetables and synchronize their data in a variety of ways. You can concatenate timetables vertically or horizontally, but only when they contain the same row times or

Use the times function to combine categorical arrays, including ordinal categorical arrays and arrays with undefined elements. When you call times on two categorical arrays, the output is

Store text from a file as a string array, sort the words by their frequency, plot the result, and collect basic statistics for the words found in the file.

Extract the contents of a table using curly braces or dot indexing.

Compare the memory required to store data as a cell array of character vectors versus a categorical array. Categorical arrays have categories that are defined as character vectors, which

Split power outage data from a table into groups by region and cause of the power outages. Then it shows how to apply functions to calculate statistics for each group and collect the results in a

Add and subtract date and time values to calculate future and past dates and elapsed durations in exact units or calendar units. You can add, subtract, multiply, and divide date and time

Convert a variable in a table from a cell array of character vectors to a categorical array.

String arrays were introduced in R2016b. String arrays store pieces of text and provide a set of functions for working with text as data. You can index into, reshape, and concatenate strings

Resample and aggregate data in a timetable. A timetable is a type of table that associates a time with each row. A timetable can store column-oriented data variables that have different data

Compare datetime and duration arrays. You can perform an element-by-element comparison of values in two datetime arrays or two duration arrays using relational operators, such as > and < .

Use the linspace function to create equally spaced datetime or duration values between two specified endpoints.

Create a categorical array. categorical is a data type for storing data with values from a finite set of discrete categories. These categories can have a natural order, but it is not required.

Combine two categorical arrays.

Group scattered data points based on their proximity to points of interest.

Create a line plot with datetime values on the x -axis. Then, change the format of the tick labels and the x -axis limits.

Access and modify table properties for variable units, descriptions and names. You also can edit these property values using the Variables Editor.

Create a timetable, combine timetables, and adjust the data from multiple timetables to a common time vector. The common time vector can contain the times from either or both timetables, or

Add a duration or calendar duration to a datetime to create a sequence of datetime values.

Create a regular timetable from one that has missing, duplicate, or nonuniform times. A timetable is a type of table that associates a time-stamp, or row time , with each row of data. In a

String arrays can contain both empty strings and missing values. Empty strings contain zero characters and display as double quotes with nothing between them ( "" ). You can determine if a

Plot data from a categorical array.

Compare text in character arrays and string arrays in different ways. String arrays were introduced in Release 2016b. You can compare string arrays and character vectors with relational

Create an ordinal categorical array using the categorical function with the 'Ordinal',true name-value pair argument.

There are two ways to represent text in MATLAB®. You can store text in character arrays. A typical use is to store short pieces of text as character vectors . And starting in R2016b, you can also

Create a line plot with duration values on the x -axis. Then, change the format of the tick labels and the x -axis limits.

A timetable is a type of table that associates a time with each row. You can subscript into a timetable to select subsets of its data in a number of different ways. To select timetable rows with

Use uniquetol to find the average z -coordinate of 3-D points that have similar (within tolerance) x and y coordinates.

Use the colon (:) operator to generate sequences of datetime or duration values in the same way that you create regularly spaced numeric vectors.

Work with a categorical array with protected categories.

Techniques for accessing data in arrays stored within cells of cell arrays.

Basic techniques and functions for working with matrices in the MATLAB® language.

Remove data from individual cells, and how to delete entire cells from a cell array.

Work with arrays having more than two dimensions. Multidimensional arrays can be numeric, character, cell, or structure arrays.

Add and delete rows in a table. You can also edit tables using the Variables Editor.

Analyze bicycle traffic patterns from sensor data using the timetable data container to organize and preprocess time-stamped data. The data come from sensors on Broadway Street in

Compares cell and structure arrays, and shows how to store data in each type of array. Both cell and structure arrays allow you to store data of different types and sizes.

Create a structure array. A structure is a data type that groups related data using data containers called fields. Each field can contain data of any type or size.

Perform calculations on tables.

Find, clean, and delete table rows with missing data.

You can use function handles as input arguments to other functions, which are called function functions . These functions evaluate mathematical expressions over a range of values. Typical

Do some basic matrix manipulations in MATLAB®.

MATLAB® considers function handles that you construct from the same named function to be equal. The isequal function returns a value of true when comparing these types of handles.

Create a cell array using the {} operator or the cell function.

You can convert datetime arrays to represent points in time in specialized numeric formats. In general, these formats represent a point in time as the number of seconds or days that have

Tables and timetables provide ways to label the rows in your data. In tables, you can label the rows with names. In timetables, you must label the rows with dates, times, or both. Row names are

Read and write data to and from a cell array.

Fill in gaps in timetable variables, using different methods for different variables. You can specify whether each timetable variable contains continuous or discrete data using the

You can use the table data type to collect mixed-type data and metadata properties, such as variable name, row names, descriptions, and variable units, in a single container. Tables are

Add cells to a cell array.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Contact your local office