MATLAB Examples

Every variable in MATLAB® is an array that can hold many numbers. When you want to access selected elements of an array, use indexing.

Welcome to this MATLAB Video tutorial. If you have never used MATLAB before, this demonstration will get you started and show you where to go to next to learn more.

MATLAB is an abbreviation for "matrix laboratory." While other programming languages mostly work with numbers one at a time, MATLAB® is designed to operate primarily on whole matrices and

MATLAB® provides a large number of functions that perform computational tasks. Functions are equivalent to subroutines or methods in other programming languages.

When you are working with text, enclose sequences of characters in single quotes. You can assign text to a variable.

To create two-dimensional line plots, use the plot function. For example, plot the value of the sine function from 0 to 2\pi :

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,

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

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

Example spreadsheet from a brain imaging study

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

This example was authored by the MathWorks community.

The test along with its experimental results is described in:

Test to have one integer

Flip multiple matrices along specified dimensions.

This function clears all empty variables from the current workspace.

Add the cell of names to a string

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

Test to have one double

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.

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

Place the UserDefinedConstants directory on your MATLAB search path

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.

Fit a polynomial curve to a set of data using polyfit. Use the polyfit function to find the coefficients of a polynomial that fits a set of data in a least-squares sense using the syntax

Copyright 2017 The MathWorks, Inc.

Define a function that visualizes the results of bfsearch and dfsearch by highlighting the nodes and edges of a graph.

If you have a set of N points on a cartesian plane, there will always exist an N-1th order polynomial of the form y = a_0 + a_1.x + a_2.x^2 + ... a_n-1.x^(n-1) which passes through all the points.

Introducing fplot for disco...

Now that we can generate a forecast for future electricity demand, the next question is what actions should we take based on that forecast? One area of interest is how to operate a combination

This live script covers the concepts of antiderivatives and integrals.

Gaussian fit using the least-squared solution in presence of known covariance

Number of rows in healthy file must be the same as the number of rows in disease file. This reflects the fact that both must have measured the same number of quantities (genes, compounds, bugs,

本プログラムでは、MATLAB上でSegNetを構築・学習し、 学習済みネットワークを評価するところまでのワークフローを試行します。 画像データは血液塗抹標本画像を利用し、写っている寄生虫の部分、赤血球の部分と それ以外の領域の3クラスに分類することを目的とします。 画像データは米国CDC DPDx Parasite Image

Medical image segmentation using texture analysis

Abstract:

Beta is vector of regressors P(beta|D) ~ N(beta| mu, lambda) mu = lambda * X{transpose} * big_sigma^(-1) * Y lambda = (X{transpose} * inv(sigma) * X + inv(big_omega))^{-1}

This tutorial shows how to perform a Reliability Based Optimization on a cantilever beam. The goal of this tutorial is to optimize a clamped beam under tip load considering uncertainties.

F. Moisy, 9 july 2008. University Paris Sud.

Regress_Bivariate:

Use linear programming and mixed-integer linear programming techniques to determine which bonds should be purchased to cover a given a cash flow in order to meet payout obligations, say for

Use array indexing to rasterize text into an existing image.

Create an animation of two growing lines. The animatedline function helps you to optimize line animations. It allows you to add new points to a line without redefining existing points.

This is an example showing standard markers available in MATLAB® plots.

How to create animations and animated GIFs in MATLAB®. In this example, we will animate the motion of a double-pendulum. We solve the ordinary differential equation using ode45.

This is an example showing standard colors available in MATLAB® plots.

Flow cytometry is a method for quantitating components or structural features of cells primarily by optical means. Although it makes measurements on one cell at a time, it can process

This is an example showing standard line styles available in MATLAB® plots.

How to create a rose plot in MATLAB®.

This function provides an option between the legend and text or annotation commands for labeling data that you plot. Edward Tufte says that data shouldn't stray far from its label, because

How to create a 3D mesh plot in MATLAB®.

File describes how anyone, even you! can create a map of sea level rise using data from the University of Colorado's Sea Level Research Group.

How to create an errorbar plot in MATLAB®.

From this post on the MATLAB Graphics blog .

How to create an inset plot within another plot in MATLAB®.

How to create a surface plot in MATLAB®.

How to create subplots with multiple plot types in MATLAB®.

How to create a 3D scatter plot in MATLAB®.

How pcolor and surf offset data by one half pixel and discard one row and one column of data. This example shows the effect in pcolor, but the results will be the same with surf.

A few examples of 3-d image smoothing through multivrant kernel regression: ksrmv.

How to display a simple image in MATLAB®.

How to create a polar plot from a function in MATLAB®.

How to create a 2D quiver plot in MATLAB®.

Write a script that tests a function that you create. The example function computes the angles of a right triangle, and you create a script-based unit test to test the function.

Perform modal and transient analysis of a tuning fork.

Analyze an idealized 3-D mechanical part under an applied load using Finite Element Analysis (FEA). The objective of the analysis is to determine the maximal deflection caused by the load.

The function NATSORT sorts a cell array of strings (1xN char), taking into account any number values within the strings. This is known as a natural order sort or an alphanumeric sort. Note that

This finite element thermal analysis (FEA) examines the heat tolerance for a robotics component of a commercial youBot.

Perform a parameter sweep of material properties to determine the material with minimum deflection caused by a given load. Lastly, for such material we compute a load deflection curve. This

The function NATSORTROWS sorts the rows of a cell array of strings (1xN char), taking into account any number values within the strings. This is known as a natural order sort or an alphanumeric

The nanimresize function resizes an image using the Image Processing toolbox function imresize, but first fills NaNs to prevent missing data along NaN boundaries.

The function LINDEX converts the subscript index output from MATLAB's inbuilt MIN and MAX functions into linear indices. The linear indices are such that when used on the same array that was

Solves a 2nd order wave equation: utt = uxx + uyy, with u = 0 on the boundaries. It uses a 2nd order central finite difference in time and a Chebyshev spectral method in space (using FFT). The code

This is a parameter sweep study of a 2nd order ODE system.

This demo illustrates a simple approach to provide taxonomy annotation of BLAST hits. It requires the taxonomy information included in the files gi_taxid_prot.dmp and nodes.dmp, which

The function NUM2WORDS converts a numeric scalar into a string with the number value given in English words, e.g. 1024 -> 'one thousand and twenty-four'. Optional arguments control the

The function ROUND60063 rounds the input numeric values to values from the IEC 60063 "Preferred Numbers" series. Most importantly ROUND60063 simulates the tolerance range of electronic

Adaptively evaluate a function on a given range. There are different methods which can be used for choosing where to add new data points. The default method provided by 'adaptive.m' is to add

Only scalar variables need apply. Matrices and vectors would not be terribly difficult to implement, but I've not done so.

This function prints some quick statistics about a variable in the command window.

The function WORDS2NUM converts a string (with a number given in English words) into a numeric value, e.g. 'one thousand and twenty-four' -> 1024. Optional arguments control many string

Code File

The imagescn behaves just like imagesc, but makes NaNs transparent, sets axis to xy if xdata and ydata are included, and has more error checking than imagesc.

This demo illustrates how you would set up and solve an optimization problem (constrained non-linear minimization).

The errorshade function plots a shaded region to indicate gaussian uncertainty. This function works by generating an RGB image of a specified color, and setting transparency of the RGB

Write a unit test for a MATLAB® function, quadraticSolver.m.

Write a unit test for a couple of MATLAB® figure axes properties using fresh fixtures and file fixtures.

We will now look at defining methods in the class definition file which are the operations that we can carry out with the class.

The following document was built from posts written for the blog "Loren on the Art of MATLAB". The ideas presented below in anonymous functions have been written as .m files so that they might

The function NATSORTFILES sorts a cell array of filenames or filepaths (1xN char), taking into account any number values within the strings. This is known as a natural order sort or an

QRcode_gen can generate QR-Codes based on the zxing libraries (http://github.com/zxing). For this purpose it will import all necessary jar files on the fly from a maven repository server

The function COLORNAMES matches the input RGB values or color name strings to the closest colors from the selected palette. COLORNAMES returns the same outputs whether matching names or

This example shows how to generate code from packData and unpackData

This contribution presents a small tool to trace calls to methods and functions. There was no tracing tool for Matlab to find on the Internet and still isn't?

Treatment of whitespace and character classes.

We are going to create a class to describe the sensor array data set. First we will look at specifying the properties. You define a class in MATLAB with a class definition file.

Pack and unpack data using the provided packData and unpackData functions

This presentation proceeds in stages, each version an extension of its predecessor (bootstrapping). The development stops well short of an industrial compiler but that is not because of

Ïnteger weights of items

QRcode_gen can generate QR-Codes based on the zxing libraries ( http://github.com/zxing ). For this purpose it will import all necessary jar files on the fly from a maven repository server

The Grammar Executing Machine principle has been demonstrated in Chapter 1. The version 0 driver gem0.m and MEX files iog0.c and iog0.h provide no-frills code that runs on the edge of

Up until now the emphasis has been on choosing new capabilities expressed first as bootstraps, then building the capabilities into GEM itself. The final built-in capability of GEM added

All compilers have to connect to the underlying hardware. That in turn requires knowing where the bits need to go. It isn't always fun, but that is what compiler writers do.

The limitation of 52 phrase names and the ursurpation 1/2 of them for Kleene*, and 8 of them for built-in character classes, is the last of the tasks set in Chapter 1. It would be nice to play the

This is the most useful diagram for visualizing the contest. It shows the dramatic improvements that occur over time. Each passing entry is a dot, with its submission time on the x-axis and

This script uses the class definition TestClass to create instances of TestClass and to clone its instances.

To monitor an object you first need to add an event to the class definition of the object, such as in this example. (see ev.m). Here we add an event called SavedData to this class which denotes

The function 'readImages' reads dicom image data from an image file or folder. Important attributes are stored in a convenient structure, which is used as the input for many other MATLAB

This is a Matlab GUI designed to view the points used in the kernels for interpolation purposes in the meshless formulation (resolution of boundary value problems).

Copyright 2015-2018 The MathWorks, Inc.Published with MATLAB® R2017a

Copyright 2017-2018 The MathWorks, Inc.Published with MATLAB® R2017a

Abaqus2Matlab is a Matlab toolbox which is used to retrieve the results of an Abaqus analysis in an easy to handle form. It is developed by George Papazafeiropoulos

The class uigage can be used in a GUI to display outputs that are suitable for a needle gage type display. It behaves in a very similar fashion to other Matlab uicontrol objects. Many

Copyright 2012-2018 The MathWorks, Inc.Published with MATLAB® R2017a

Simulation of acoustic beams from monoelement transducers is possible by using the objects, outside the NumSim simulation program. The visualization can be done using a GUI in Matlab or in

This is a Matlab GUI designed to compute the acousto-electric conductivity modulation signal and Debye signals for a given electric geometry. Different parameters are included in this GUI

Find the maximum value of a single variable in a data set using mapreduce. It demonstrates the simplest use of mapreduce since there is only one key and minimal computation.

Use the readtable function to import mixed data from a text file into a table. Then, it shows how to modify and analyze the data in the table.

Use mapreduce to carry out simple logistic regression using a single predictor. It demonstrates chaining multiple mapreduce calls to carry out an iterative algorithm. Since each

Compute the mean of a single variable in a data set using mapreduce. It demonstrates a simple use of mapreduce with one key, minimal computation, and an intermediate state (accumulating

Visualize patterns in a large data set without having to load all of the observations into memory simultaneously. It demonstrates how to compute lower volume summaries of the data that are

Compute the mean by group in a data set using mapreduce. It demonstrates how to do computations on subgroups of data.

Extract a subset of a large data set.

Compute the mean and covariance for several variables in a large data set using mapreduce. It then uses the covariance to perform several follow-up calculations that do not require another

Compute summary statistics organized by group using mapreduce. It demonstrates the use of an anonymous function to pass an extra grouping parameter to a parameterized map function. This

Compute a tall skinny QR (TSQR) factorization using mapreduce. It demonstrates how to chain mapreduce calls to perform multiple iterations of factorizations, and uses the info argument of

Use high-level MATLAB® functions to import the sample CDF file, example.cdf . High-level functions provide a simpler interface to accessing CDF files.

Use ImageDatastore and mapreduce to find images with maximum hue, saturation and brightness values in an image collection.

Use the findgroups and splitapply functions to calculate grouped statistics of a tall timetable containing power outage data. findgroups and splitapply enable you to break up tall

Create a datastore for key-value pair data in a MAT-file that is the output of mapreduce . Then, the example shows how to read all the data in the datastore and sort it. This example assumes that

Create text files, including combinations of numeric and character data and nonrectangular files, using the low-level fprintf function.

Use low-level functions to read data from a CDF file. The MATLAB® low-level CDF functions correspond to routines in the CDF C API library. To use the MATLAB CDF low-level functions

Create a datastore for a collection of images, read the image files, and find the images with the maximum average hue, saturation, and brightness (HSV). For a similar example on image

Import comma-separated numeric data from a text file, using the csvread function.

Create two different memory maps, and then read from each of the maps using the appropriate syntax. Then, it shows how to modify map properties and analyze your data.

To export a table in the workspace to a Microsoft® Excel® spreadsheet file, use the writetable function. You can export data from the workspace to any worksheet in the file, and to any location

Fit data with a linear model containing nonpolynomial terms.

Use low-level functions to write data to a NetCDF file. The MATLAB® low-level functions provide access to the routines in the NetCDF C library. MATLAB groups the functions into a package,

Create a datastore for a large text file containing tabular data, and then read and process the data one chunk at a time or one file at a time.

Use tall arrays to work with big data in MATLAB®. You can use tall arrays to perform a variety of calculations on different types of data that does not fit in memory. These include basic

MATLAB provides you with the tools to import spreadsheet data both interactively and programmatically. To interactively import spreadsheet data, see docid:import_export.br81u9o .

Use the datastore and mapreduce functions to process a large amount of file-based data. The MapReduce algorithm is a mainstay of many modern "big data" applications. This example operates

Read an arbitrary format text file with textscan . This function allows you to read the file one block at a time, and each block can have a different format.

Open a MATLAB file

Open the folder containing the current file

Example 1: addcd, show, reset

Open the current working directory

This Live Script file will be presented to your end user in the Live Editor just as you see it here. You can take advantage of all of the features of Live Script to present information and

Go up one level

This script demonstrates the complete workflow for developing an embedded machine learning application,including acquiring the data, extracting features, exploring various

This Matlab tutorial demonstrates step by step the multivariate singular spectrum analysis. The steps are almost similar to those of a singular spectrum analysis.

This Matlab tutorial demonstrates step by step the Singular Spectrum Analysis (SSA).

必要なToolbox:

Author: Shujaat Khan, shujaat123@gmail.com Please Cite: Khan, S., Naseem, I., Togneri, R. et al. Circuits Syst Signal Process (2017) 36: 1639. doi:10.1007/s00034-016-0375-7

Plant identification simulation Author: SHUJAAT KHAN (shujaat123@gmail.com) Please cite: @article{Khan2017FLMFFL, title={FLMF: Fractional least mean fourth algorithm for channel

Illustrates the use of BEADS to estimate and remove the baseline of chromatogram series.

This Matlab tutorial demonstrates the application of a modified varimax algorithm in varimax.m to the eigenvectors of a multichannel singular spectrum analysis (M-SSA).

Khan, S., Naseem, I., Togneri, R. et al. Circuits Syst Signal Process (2017) 36: 1639. doi:10.1007/s00034-016-0375-7 https://link.springer.com/article/10.1007/s00034-016-0375-7

This is short demo that loads and renders a 3D model of a human femur. It showcases some of MATLAB's advanced graphics features, including lighting and specular reflectance.

Collect acceleration data from an Android device and use it to count the number of steps taken.

Collect position data from an Android device and display it on a map. Latitude and longitude coordinates are used to mark the device's route. Speed information is used to add color to the

Plot data from multiple sensors on an Android device together in one timeline. Measurements of angular velocity and orientation will be collected from the device and plotted over absolute

Collect position data from an Apple iOS device and display it on a map. Latitude and longitude coordinates are used to mark the device's route. Speed information is used to add color to the

Collect acceleration data from an Apple iOS device and use it to count the number of steps taken.

Plot data from multiple sensors on an Apple iOS device together in one timeline. Measurements of angular velocity and orientation will be collected from the device and plotted over absolute

Use the MATLAB® Support Package for Arduino® Hardware to use SPI interface to communicate with MCP42010 Digital Potentiometer.

Use the MATLAB® Support Package for Arduino® Hardware to control servo motors, DC motors and stepper motors using Adafruit motor shield v2.

Use the MATLAB® Support Package for Arduino® Hardware and the I2C interface to communicate with I2C devices.

Use MATLAB® Support Package for Arduino® Hardware to perform basic operations on the hardware such as turning an LED on and off, blinking LEDs and playing sound on a speaker.

Use the MATLAB® Support Package for Arduino® Hardware to steer a two-wheel Arduino-based robot with closed-loop control.

Use the MATLAB® Support Package for Arduino® Hardware to control multiple LEDs with two 74HC595 8-bit serial-in-parallel-out shift registers.

Use the MATLAB® Support Package for Arduino® Hardware to control a hobby servo motor.

Use the MATLAB® Support Package for Arduino® Hardware to control servo motors, DC motors, and stepper motors using the Adafruit Motor Shield V2.

Use the MATLAB® Support Package for Arduino® Hardware to collect large number of push button states with a 74HC165 8-bit parallel-in-serial-out shift register. This example uses four push

Use the MATLAB® Support Package for Arduino® Hardware to control a 12-step rotary encoder with a built-in push button.

Use the MATLAB® Support Package for Arduino® Hardware to control a 1-Digit 7-Segment display with a 74HC595 8-bit serial-in-parallel-out shift register.

Use the serial UART on BeagleBone Black hardware to control a 4-digit 7-segment display.

Use MATLAB to process images captured from a web camera on BeagleBone Black® board to track a green ball.

Use the SPI peripheral on BeagleBone Black® hardware to connect to an MCP3008 10-bit 8-channel ADC.

Use the I2C peripheral on BeagleBone Black® hardware to control a 4-digit 7-segment display.

You basics of working with BeagleBone Black® Hardware.

Use the MATLAB® Support Package for BeagleBone Black® Hardware to perform basic operations on the hardware such as executing shell commands, turning an on-board LED on or off and

Implement a closed-loop control algorithm to make a two-wheel LEGO® MINDSTORMS® EV3™ vehicle drive straighter.

Write a MATLAB script to implement a collision alarm with LEGO® MINDSTORMS® EV3™ hardware.

Interact with the EV3 brick peripherals, read a sensor value, and control a motor.

Set up communications with the EV3 brick.

Build a digital voltmeter using MATLAB® Support Package for Raspberry Pi® Hardware.

Build a motion sensor camera using MATLAB® Support Package for Raspberry Pi® Hardware.

Use MATLAB to process images captured from a Raspberry Pi Camera Board module to track a green ball.

Increase the number of digital I/O pins by connecting a MCP23017 I/O expander chip to the Raspberry Pi® hardware.

Capture and process images from Raspberry Pi® Camera Board module using the MATLAB® Support Package for Raspberry Pi Hardware.

Use the I2C peripheral on Raspberry Pi® hardware to control a 4-digit 7-segment display.

Use the MATLAB® Support Package for Raspberry Pi® Hardware to perform basic operations on the hardware such as executing shell commands, turning an on-board LED on or off and manipulating

Use the serial UART on Raspberry Pi hardware to control a 4-digit 7-segment display.

Use the SPI peripheral on Raspberry Pi® hardware to connect to an MCP3008 10-bit 8-channel ADC.

You basics of working with Raspberry Pi® Hardware.

Read the sensor values, read the position of joystick and control the LED Matrix on Raspberry Pi® Sense HAT using MATLAB® Support Package for Raspberry Pi Hardware.

Use MATLAB® to read the accelerometer on the Raspberry Pi Sense HAT and control the rotation of the image displayed on the LED matrix.

Use the snapshot function to acquire live images from USB Webcams.

Use the snapshot function to acquire live images and log the video to disk.

Copyright 2013 The MathWorks, Inc.Published with MATLAB® R2013a

Use the MATLAB® Support Package for Arduino® Hardware to control a HC-SR04 ultrasonic ranging module capable of measuring distances in the 2cm to 400cm range.

The data is a measurement from a class room The documentation of the measurement is found at http://legacy.spa.aalto.fi/projects/poririrs/

Original reference to the cell list algorithm: Heinz, T.N. & Hunenberger, P.H. "A fast pairlist-construction algorithm for molecular simulations under periodic boundary conditions." J

RotmanTrader - connects to and manages data and trading through Rotman Interactive Trader

The Critical flutter velocity is computed for 2 single-span suspension bridges: One with a main span of 1.2 km and the other one with the main span of 0.45 km. The coupling of the lateral,

Use the MATLAB® Support Package for Arduino® Hardware to control a three axis LSM303 accelerometer and magnetometer.

Use the MATLAB® Support Package for Arduino® Hardware to communicate with DS18B20 temperature sensor and DS2431 EEPROM

The data are room impulse responses measured in a control room type space in home environment.

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:

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