com.mathworks.matlab.types.CellStr class

Package: com.mathworks.matlab.types

Java class to represent MATLAB cell array of char vectors

Description

The CellStr class provides support for passing data from Java® to MATLAB® as a MATLAB cell array of char vectors (called a cellstr in MATLAB, see cellstr). There are MATLAB functions that require cell arrays of char vectors as inputs. To pass arguments from Java to a MATLAB function requiring cellst inputs, use the Java CellStr class to create a compatible type.

A MATLAB cellstr is mapped to a Java String array.

Constructor Summary

CellStr(Object stringArray) creates a CellStr using a String or String array. The String array can have multiple dimensions.

Method Summary

Object getStringArray()

Get the String or String array used to create the CellStr.

boolean equals(CellStr1,CellStr2)

Compare one CellStr instance with another. Two CellStr instances are equal if the String or String array they contain are the same.

Examples

Construct CellStr

This example constructs a CellStr named keySet and puts the variable in the MATLAB base workspace.

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

class javaCellstr {
    public static void main(String[] args) throws Exception {
        MatlabEngine eng = MatlabEngine.startMatlab();
        CellStr keySet = new CellStr(new String[]{"Jan","Feb","Mar","Apr"});
        eng.putVariable("mapKeys",keySet);
        eng.close();
    }
}

Construct CellStr Array

This example creates a CellStr array and passes it to the MATLAB plot function to change the appearance of the graph produced by MATLAB. The call to the MATLAB print function exports the figure as a jpeg file named myPlot.jpg.

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

class CellStrArray {
    public static void main(String[] args) throws Exception {
        MatlabEngine eng = MatlabEngine.startMatlab();
        String[][] strArray = new String[2][2];
        strArray[0][0] = "MarkerFaceColor";
        strArray[0][1] = "MarkerEdgeColor";
        strArray[1][0] = "green";
        strArray[1][1] = "red";
        CellStr markerCellStr = new CellStr(strArray);
        eng.putVariable("M",markerCellStr);
        eng.eval("plot(1:10,'--bs',M{:})");
        eng.eval("print('myPlot','-djpeg')");
        eng.close();
    }
}
Introduced in R2016b