开发者

asp.net and matlab

I have successfully developed an application in asp.net which calls a matlab function and produce开发者_C百科s the results as an integer...the problem is I need to pass this value back to asp.net to proceed with the further process as to which page to redirect.


I'm guessing you are using the NE Toolbox?

If so, in C# this is how you would do it.

Matlab Function cellexamp.m:

function out = OutInt
num = 10;
out = { num };

Run deploytool in Matlab

MATLAB Builder for .NET -> .NET Component Project/Component name: MyOutIntProject Class name: MyOutIntClass

C#:

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

namespace IntTest
{
    class CellExampleApp
    {
        static void Main(string[] args)
        {
            MWCellArray myIntCell = null;
            try
            {
                MyOutIntClass obj = new MyOutIntClass();
                myIntCell = (MWCellArray)obj.OutInt();

                MWNumericArray item = (MWNumericArray)cellexp[1];

                Console.WriteLine("item is {0}", item);

                double[,] native = (double[,])item.ToArray(MWArrayComponent.Real);            
                Console.ReadLine();
        }

        catch (Exception exception)
        {
            Console.WriteLine("Error: {0}", exception);
        }
    }
}

}

Even though your num variable seems to be an int, Matlab moves everything back and forth through its MWNumericArray. Your native[0,0] variable will be '10' in this case.

This example shows This shows how to use MWArray.dll for moving strings, arrays and ints

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜