does the matlab R2017a deploy neural network for c#(.net Assemly)
2 views (last 30 days)
Show older comments
wahed fazeli
on 28 Dec 2017
Commented: Kojiro Saito
on 10 Jan 2018
i use matlab R2017a but when i want to deploy my code to c#(.net assembly) it has a lot of error my code is very simple but i dont know why the matlab dont compile it in c#(.net assembly) these are snapshots of error in compiling neural network.
does the c# visual studio run my code with this errors because the matlab created files specially dll file(does this dll file work in the visual studio?) this is my simple code of neural network
function neuralnetwork(x,t)
net= fitnet(10);
disp('Training fitnet');
train(net,x,t);
end
does this version just have this problem?
0 Comments
Accepted Answer
Kojiro Saito
on 30 Dec 2017
Edited: Kojiro Saito
on 10 Jan 2018
From R2017a, a feature was added to MATLAB Compiler to show warnings if unsupported functions are used in compiled scripts. But there's an issue in R2017a that many warnings of unsupported Fixed-Point Designer (toolbox/fixedpoint/fixedpoint) will be shown in PackagingLog.html even though those functions of Fixed Point Designer are not used in compiled MATLAB scripts. I think this issue was solved in R2017b.
So, you can ignore the warnings of "toolbox/fixedpoint/fixedpoint" in PackagingLog.html because you don't use Fixed-Point Designer functions in your neuralnetwork.m. I confirmed your script is able to compile and run as a standalone, so I think there's no issue for .NET assembly.
UPDATED:
I also tested with MATLAB R2017a and .NET (Console application) and it worked fine.
I have compiled as .NET assembly from your neuralnetwork.m, specifying appname "neuralnetwork" as the attached screenshot.
Here is a sample #C code.
Program.cs
using System;
using MathWorks.MATLAB.NET.Arrays;
using neuralnetwork;
namespace neuralnetwork
{
class neuralnetworkClass
{
static void Main(string[] args)
{
Class1 obj = null;
MWNumericArray arrayX = null;
MWNumericArray arrayT = null;
MWArray[] result = null;
int numOfOutput = 0;
try
{
// Instantiate your component class.
obj = new Class1();
// Invoke your component.
arrayX = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
arrayT = new double[]{0, 0.84, 0.91, 0.14, -0.77, -0.96, -0.28, 0.66, 0.99};
result = obj.neuralnetwork(numOfOutput, arrayX, arrayT);
// print the output.
Console.WriteLine("Neural Network Done");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
You need to do the following.
1. Add two dll files (compiled neuralnetwork.dll and $MATLAB\toolbox\dotnetbuilder\bin\win64\v4.0\MWArray.dll) to the Reference of your .NET solution file in Visual Studio.
2. Specify Platform target to 64bit in Visual Studio.
Hope this help.
0 Comments
More Answers (1)
wahed fazeli
on 9 Jan 2018
1 Comment
Kojiro Saito
on 10 Jan 2018
I tested with compiled .NET dll (in MATLAB R2017a) and worked. I have updated the above answer with sample C# program.
See Also
Categories
Find more on MATLAB Compiler SDK in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!