Creating a .NET List<List<double>> to call a .NET DLL from MATLAB?

Matt

I have a .NET DLL I'm loading into MATLAB R2016B through the asm = NET.addAssembly('C:\My.dll') It is fairly easy to create a .NET list of doubles using netDouble = NET.createGeneric('System.Collections.Generic.List',{'System.Double'},1) which MATLAB shows as 1x1 List<System*Double>, but there is no tutorial out there that shows how to create a .NET List<List<double>> structure. MATLAB can't access the code I need to run as a result - it shows the error as: Value must be 'System.Collections.Generic.List<System*Collections*Generic*List<System*Double>>'.

Anyone out there know how to create the above structure? Much appreciated.

Matt

Actually MATHWORKS tech support got back to me with a solution that works. Since I don't see it documented anywhere, I'm posting this example in case someone else runs into this issue:

genCls = NET.GenericClass('System.Collections.Generic.List','System.Double');
obj = NET.createGeneric('System.Collections.Generic.List',{genCls},5);

And how they explained it: In this method, we first create a generic class as List and this class is provided as an argument to the 'NET.createGeneric' method hence the created list is of type List<List<double>>

Then to populate it... here's a function I wrote to take the Matlab array and convert to the proper type all rolled into 1:

function [NETobj] = ML_NET_ListListDouble(MLarray)  
genCls = NET.GenericClass('System.Collections.Generic.List','System.Double');
NETobj = NET.createGeneric('System.Collections.Generic.List',{genCls},size(MLarray,1));    
for i=1:size(MLarray,1) 
        obj1 = NET.createGeneric('System.Collections.Generic.List',{'System.Double'},size(MLarray,2));
        AddRange(obj1, NET.convertArray(MLarray(i,:))) %insert the current MATLAB row into the NET structure
    Add(NETobj, obj1)
end
end

That function hopefully comes in useful for someone else - a brainless conversion from a MATLAB array to a .NET <List<List<double>>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

List non-.NET DLL functions from C#

From Dev

How to call a list declared in VB.net from aspx

From Dev

Return list to ajax call from controller asp.net

From Dev

Convert DataTable to List<double> in R.NET

From Dev

JNI to call .NET dll

From Dev

pythonnet cannot call method from vb .net dll - TypeError

From Dev

How to call .NET DLL from Inno Setup using DNNE?

From Dev

Call .Net C# DLL method from Classic ASP

From Dev

How call method from custom .net dll in vbscript

From Dev

Matlab creating a design of experiment list

From Dev

Creating a nested list from a list

From Dev

Use template layout for list elements in ASP.NET for results from jquery API call

From Dev

Call a model not from database to list ASP.NET Core 5 MVC

From Java

Creating doubly linked list(DLL) from a basic linked list-Composition or inheritance?

From Dev

Creating a Drop Down List in ASP.NET MVC

From Dev

Creating an updatable list of items with Asp.Net MVC and SignalR

From Dev

Creating dataframe from a list

From Dev

creating list from dataframe

From Dev

creating a board from a list

From Dev

Creating a graph from the list

From Dev

Creating a list from a for loop

From Dev

Creating a list from list of a list in python

From Dev

Creating a list of dictionaries from a list of list

From Dev

Get values from .NET controls to SharePoint List

From Dev

ASP NET select object from list

From Dev

Pairs from a list of string in vb.net

From Dev

Filter Dictionary from list in vb.net

From Dev

Deserialize in a list from JSON to VB.NET

From Dev

Implementing checkbox list from list in ASP.NET Core