Main Content

com.mathworks.matlab.types.CellStr

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.

Creation

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

Methods

Public Methods

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

expand all

  • Construct a CellStr named keySet and put 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();
        }
    }
  • Create a CellStr array and pass 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