Main Content

com.mathworks.matlab.types.Struct

Java class to pass MATLAB struct to and from MATLAB

Description

The Struct class provides support for passing data between MATLAB® and Java® as a MATLAB struct. The Struct class implements the java.util.Map interface.

The Struct class is designed as an immutable type. Attempting to change the mappings, keys, or values of the returned Struct causes an UnsupportedOperationException. Calling these methods can cause the exception: put(), putAll(), remove(), entrySet(), keySet(), and values().

For an example, see Using MATLAB Structures in Java.

Creation

Struct s = new Struct("field1",value1,"field2",value2, ...) creates an instance of Struct with the specified field names and values.

Methods

Public Methods

containsKey(Object key)

Returns true if this map contains a mapping for the specified key.

containsValue(Object value)

Returns true if this map maps one or more keys to the specified value.

entrySet()

Returns a Set view of the mappings contained in this map.

equals(Object o)

Compares the specified object with this map for equality.

get(Object key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

hashCode()

Returns the hash code value for this map.

isEmpty()

Returns true if this map contains no key-value mappings.

keySet()

Returns a Set view of the keys contained in this map.

size()

Returns the number of key-value mappings in this map.

values()

Returns a Collection view of the values contained in this map.

Examples

expand all

Create a Struct and assign a key and value.

import com.mathworks.engine.*;
import com.mathworks.matlab.types.*;

class StructProperties {
    public static void main(String[] args) throws Exception {
        MatlabEngine eng = MatlabEngine.startMatlab();
        int[] y = {1,2,3,4,5};
        double[] color = {1.0,0.5,0.7};
        Struct s = new Struct("Color",color,"LineWidth",2);
        eng.feval("plot",y,s);
    }
}

Version History

Introduced in R2016b