phuc
phuc

Reputation: 1

I don't compile C# tutorial with Matlab engine

I write a tutorial C# API with Matlab using matlab.engine. (I want to exchange data between C# and Matlab. However, I cannot use the library when compiling. How to hide error? My code here:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

using MathWorks.MATLAB.Engine;
using MathWorks.MATLAB.Exceptions;
using MathWorks.MATLAB.Types;
using System;

namespace MathWorks.MATLAB.Engine.ConsoleExamples
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.Write("Starting MATLAB... ");
            using (dynamic matlab = MATLABEngine.StartMATLAB())
            {
                Console.WriteLine("done.");
                double[] A = matlab.linspace(-5.0, 5.0);
                int[] sz = new int[] { 25, 4 };
                double[,] B = matlab.reshape(A, sz);
            }
            // Call when you no longer need MATLAB Engine in your application.
            MATLABEngine.TerminateEngineClient();
        }
    }
}
namespace UDP_virtual
{
    internal static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

But I don't compile. I assume I don't add lib for C# file.

my code

Upvotes: 0

Views: 70

Answers (1)

Andrey Posohov
Andrey Posohov

Reputation: 1

At first, you must add Matlab libraries as dependencies to your project, or load libraries dynamically and use Matlab.Engine as dynamic object.

Upvotes: 0

Related Questions