简体   繁体   中英

MATLAB (.NET Assembly) Data type question: MWArray to string conversion

I am using MATLAB's integrated .NET assembly builder but I am having an issue with data types and return values.

I have compiled a small, very simple, function in MATLAB and build it for .NET.

I am able to call the namespace and even the function just fine. However, my function returns a string value, and MATLAB defaults to returning it as an MWArray object data type. However, I know that the value is a string but I can't figure out how to cast it.

My MATLAB function looks like this:

function version = get_version()
    foo ='1.0';
    bar = strcat('foo-', foo);

    version = string(bar);
end

And then in .NET I call it as:

MWArray version;
version = xClass.get_version();

whereas xClass is the name of the MATLAB built class. When I try to cast it into a string:

string str = version.ToString();
Console.WriteLine(str);

I just receive:

Internal_Matrix_Reference____ 

but not foo-1.0 as I would expect.

Does anyone have experience with the .NET builder in MATLAB that can help me with this? It is really throwing me for a loop.

Thanks a lot for your help!

Apparently, the solution is pretty easy. The Matlab function has to return the version differently:

function version = get_version()
    foo ='1.0';
    version = strcat('foo-', foo);
end

And then in .NET it works as expected:

MWArray version;
version = xClass.get_version();

string str = version.ToString();
Console.WriteLine(str);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM