MATLAB Examples

By Jarek Tuszynski

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 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

Example spreadsheet from a brain imaging study

If hot=true, the database structure is modified as needed. e.g, when you get a table with d.table('tablex'), tablex is automatically created. Similarly, when you insert entries into

This example was authored by the MathWorks community.

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

Popen() -- for "pipe open" -- is a very useful system call provided in many flavors of Unix. It runs a command passed in as a string then returns a file handle so that the parent process can read or

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

Pack and unpack data using the provided packData and unpackData functions

This example shows how to generate code from packData and unpackData

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

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

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

This paper discusses several approaches for calling shared libraries from Simulink models.

Use Python® language functions and modules within MATLAB®. The example calls a text-formatting module from the Python standard library.

Pass a MATLAB structure to the function, addStructFields .

Create a pointer to a subset of a MATLAB vector X . The new pointer is valid only as long as the original pointer exists.

Construct and pass a pointer to C function multDoubleRef .

Pass a MATLAB character array str to a C function, stringToUpper .

Pass data stored columnwise in a MATLAB array to a C function that assumes a row-by-column format.

How a C function changes the dimensions of a MATLAB array, and how to restore its shape.

Pass a MATLAB structure to a C library function, addStructByRef . When you pass the structure, MATLAB automatically converts the field types, but MATLAB also makes a copy of the fields.

Pass a multilevel pointer to a C function.

Create a MATLAB® cell array of character vectors, mlStringArray , from the output of the getListOfStrings function.

How calling the addStructByRef function with a pointer modifies the fields in the input argument.

Display information about and modify a libstruct object, c_struct .

Use pointer arithmetic to access elements of a structure. The example creates a MATLAB structure, based on the c_struct definition in the shrlibsample.h header file.

Preconvert structure sm to c_struct before calling addStructFields . If you repeatedly pass sm to functions, preconverting eliminates the processing time required by MATLAB to

Pass enumeration values to the readEnum function in the shrlibsample library. Load the library.

Add a plugin to the test runner. The matlab.unittest.plugins.TestRunProgressPlugin displays progress messages about a test case. This plugin is part of the matlab.unittest package.

Use a System.String object in a MATLAB® function.

Update a Python® list of folder names using the append method.

The class definition of a Whiteboard System object and how to use the object. Each time you run the whiteboard object, it draws a line on a whiteboard.

Analyze the information returned by a test runner created from the SolverTest test case.

Display elements in a tuple.

Evaluate the expression x+y in Python®. To evaluate an expression, pass a Python dict value for the globals namespace parameter.

Change the cursor icon in an Excel® spreadsheet.

Access an element of a Python® list variable containing list elements.

In this example, the CellModifyVisitor class implements the operations to modify the contents of cell arrays of types bool , double , and char , and contained cell arrays. You can add new

Create a Python® tuple variable with a single element. A tuple with one element has a trailing comma.

Change the height of a row, defined by a Range object, in a spreadsheet.

Create a tuple variable to pass to a Python® function.

Pass the backslash control character (\) as a Python® str type.

Display the last element in a Python® list variable. The example compares indexing into a MATLAB® cell array with indexing into a Python list.

Call the Python math.fsum function, which sums the floating-point values in an interable input argument.

Use the Python® path separator character (;). In MATLAB®, a Python character is a py.str variable.

Convert a Python® list of numeric values into a MATLAB® array of double.

Get and set values in a dictionary.

Change a value in a dict variable using the Python® update method.

Create a dict variable to pass to a Python® function.

Display elements of a Python® list.

Create a list variable to pass to a Python® function.

Create a .NET jagged array of System.Double using the NET.createArray function.

Use Python® numbers in MATLAB®. The trigonometry functions in the math module return Python float types.

Use a visitor class to define operations to perform on specific types of matlab::data::Array .

Display the first character of a Python® str variable. The example compares indexing into a MATLAB® character vector with indexing into the Python variable.

Use an incremental step in indexing.

When unit testing, you are often interested in testing a portion of a complete system, isolated from the components it depends on. To test a portion of the system, we can substitute mock

Set a static property using the NET.setStaticProperty function.

Set the number of inputs for a System object™ with and without using getNumInputsImpl.

You can inject variable inputs into your existing class-based test. To provide test data that is defined outside the test file and that should be used iteratively by the test (via

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