MATLAB Builder NE (.NET assembly) Data Type Question

I am using MATLAB Builder NE (MATLAB.NET built-in assembly collector), but I have a problem with data types.

I put together a small, very simple function in MATLAB and built it for .NET. I can call the namespace and even the function just fine. However, my function returns a value, and MATLAB returns it by default as a data type object[]. However, I know that the value is an integer, but I cannot figure out how to distinguish it.

My MATLAB function looks like this:

function addValue = Myfunction(value1, value2)

addValue=value1+value2;

end

Pretty simple right?

And then in .NET I can name it as:

xClass.addValue (1, 3, 4);

where xClass is the name of the MATLAB built-in class, but when you try:

int x = xClass.addValue (1, 3, 4);

C # error. Typical .NET casting (int) does not work. The compiler states that it cannot convert the object [] to int.

- .NET- MATLAB, ? . MATLAB BUILDER (484 !) .

+3
5

Builder NE, , - :

using MathWorks.MATLAB.NET.Utility;
using MathWorks.MATLAB.NET.Arrays;

int x = ((MWNumericArray)(xClass.addValue(1, 3, 4)).ToScalarInteger();

IntelliSense MWArray, MWCellArray, MWStructArray MWNumericArray , MATLAB.

, addValue?

+2

, , , [0] 1 . [0,0], 0.

, 7 x:

int x = ((int[,])result[0])[0,0]
+1

, . :

[0] , :

> {int[1, 1]}
>     [0, 0]: 7

"7", .: -)

0

Object [], Matlab .

Matlab NE , , Matlab MWArray, MWArray, , .

, [0] - MWArray, int.

0
source

In my particular case, I have a result double.

 double suma=((double[,])xClass.addValue(1, 3, 4)[0])[0,0];

Then you can convert to int

int x = Convert.ToInt32(suma);
0
source

Source: https://habr.com/ru/post/1739064/


All Articles