Home C# - MATLAB generic interface
Reply: 0

C# - MATLAB generic interface

galah92 Published in 2018-01-11 09:09:16Z

I'm dealing with the exact same case as the following question. I have a MATLAB process which generate information from a sensor (realtime) and I need to pass info to .NET dll, serialize (to JSON) and send. I also need the ability to deserialize JSON in C# and pass it back to MATLAB.

One limitation though - I don't have strict objects that I know I currently need to pass, meaning I need to write something generic.

When receiving JSON, I currently do

var converter = new ExpandoObjectConverter();
dynamic data = JsonConvert.DeserializeObject<ExpandoObject>(json, converter);

But now, I need a way to cast data to types that MATLAB can understand, or find a way for MATLAB to understand ExpandoObject.

I tried dealing with Newtonsoft.JSON's object in MATLAB (JToken, JObject, etc). Couldn't find a way, for example, to access all JObject's keys from MATLAB (in C# it's done using LINQ).

Note, json can be something like:

    "a": [[1, 2], [3, 4], [5, 6]],
    "b": 8,
    "c": ["aa", "bb", "cc"],
    "d": {
        "da": [1, 2, 4, 8],
        "db": true

In that case, I would like to end with a MATLAB struct such that:

data.a = [1, 2; 3, 4; 5, 6;];  % double
data.b = 8;                    % double
data.c = {'aa', 'bb', 'cc'};   % cell
data.d.da = [1, 2, 4, 8];      % double
data.d.db = true;              % logical
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30027 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO