| Contents | Index |
| On this page… |
|---|
Example of Cell Arrays of .NET Data Create a Cell Array for Each System.Object |
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:
dllPath = fullfile('c:','work','NetDocCell.dll'); asm = NET.addAssembly(dllPath); 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 cell arrays for all System.Object arrays.
Convert the .NET types to MATLAB types, according to the information in Handling Data Returned from a .NET Object.
Create MATLAB variables for each type within the cell arrays.
Call MATLAB functions with the MATLAB variables.
The following statement creates the cell array mlData:
mlData = cell(obj.getNewData)
mlData =
[1x1 System.String] [1x1 System.Object[]]This cell array contains elements of the these types.
To access the contents of the System.Object array, create another cell array mlPlotData:
mlPlotData = cell(mlData{2})mlPlotData =
[1x1 System.String] [1x1 System.Double[]]
This cell array contains elements of the these types.
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});
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);
![]() | Call .NET Methods with Optional Arguments | An Assembly is a Library of .NET Classes | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |