MATLAB Examples

Some basic examples on how to use mutliple input set functions:

Example spreadsheet from a brain imaging study

The test along with its experimental results is described in:

This video tutorial will show you how to link plots to their data sources providing a live view of a variable and how to carry out data brushing, letting you select and manipulate data

Test for the good size of a matrix containing floats

This example was authored by the MathWorks community.

Place the UserDefinedConstants directory on your MATLAB search path

Format. The user can specify any number of digits to be carried, while doing a variety of different numerical computations on these numbers. Not all MATLAB operators are defined, as my main

Test to have one integer

This function sorts input matrix A and corresponding matrices using sortrows. Output matrices are sorted such that the first output is a sorted version of A, and all other outputs are sorted

Test for the presence of a string in a list of possible values

Flip multiple matrices along specified dimensions.

This function clears all empty variables from the current workspace.

Test to have one double

Add the cell of names to a string

In this case, yes, we know exactly the final size of the array. This example is merely a time test, plus it shows that growdata produces the correct size result.

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

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.

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

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

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

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

Perform calculations on tables.

Add cells to a cell array.

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

Do some basic matrix manipulations in MATLAB®.

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

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

Add and delete column-oriented variables in a table. You also can edit tables using the Variables Editor.

Read and write data to and from a cell array.

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

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

Work with a categorical array with protected categories.

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.

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

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

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.

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

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

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.

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

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

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

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

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

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

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

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

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.

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

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.

Choose your country 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 location from the following list:

See all countries