The Wayback Machine - https://web.archive.org/web/20110930154413/http://www.mathworks.com:80/help/techdoc/matlab_external/bs3maty.html
Skip to Main Content Skip to Search
Product Documentation

Tips for Working with Cell Arrays of .NET Data

Example of Cell Arrays of .NET Data

In the Converting Nested System.Object Arrays example, the cell array mlData contains data from the MyGraph.getNewData method. By reading the class documentation in the source file, you can create the following MATLAB graph:

NET.addAssembly('c:\work\NetDocCell.dll');
obj = NetDocCell.MyGraph;

% Create cell array containing all data
mlData = cell(obj.getNewData);

% Plot the data and label the graph
figure('Name',char(mlData{1}));
plot(double(mlData{2}(2)))
xlabel(char(mlData{2}(1)));

However, keeping track of data of different types and dimensions and the conversions necessary to map .NET data into MATLAB types is complicated using the cell array structure. Here are some tips for working with the contents of nested System.Object arrays in MATLAB. After reading data from a .NET method:

Create a Cell Array for Each System.Object

The following statement creates the cell array mlData:

mlData = cell(obj.getNewData)

This cell array contains elements of the following type:

mlData = 
    [1x1 System.String]    [1x1 System.Object[]]

To access the contents of the System.Object array, create another cell array mlPlotData:

mlPlotData = cell(mlData{2})

This cell array contains elements of the following type:

mlPlotData = 
    [1x1 System.String]    [1x1 System.Double[]]

Create MATLAB Variables from the .NET Data

Assign cell data to MATLAB variables and convert:

% Create descriptive variables
% Convert System.String to char
mytitle = char(mlData{1});
myxlabel = char(mlPlotData{1});
% Convert System.Double to double
y = double(mlPlotData{2});

Call MATLAB Functions with MATLAB Variables

Create a MATLAB graph with this data:

% Remove the previous figure
close
% Plot the data and label the graph
figure('Name',mytitle,'NumberTitle','off');
plot(y)
xlabel(myxlabel);
  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A; sessions led by MATLAB experts.

 © 1984-2011- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS