【发布时间】:2015-11-06 17:43:29
【问题描述】:
我为我在 matlab 中创建的神经网络创建了一个函数。我可以在 c# 中成功加载函数,但我不知道如何输入矩阵作为输入,因为数组不起作用。
Matlab 原函数
function energy = simCW(x)
%x is a 4xQ matrix (I always sim 4x1 though)
S = load('CW100', 'CB_CW100');
CB_CW100 = S.CB_CW100;
energy = sim(CB_CW100,x')';
end
用于 C# 生成函数的 Matlab 行
genFunction(CB_CW100, 'cbcw.m', 'MatrixOnly','yes', 'ShowLinks','no')
生成函数
function [y1] = cbcw(x1)
%CBCW neural network simulation function.
% [y1] = cbcw(x1) takes these arguments:
% x = 4xQ matrix, input #1
% and returns:
% y = 1xQ matrix, output #1
% where Q is the number of samples.
C# 代码 - Source
static void Main(string[] args)
{
MLApp.MLApp matlab = new MLApp.MLApp();
double[] current = new double[4];
current[0]= 71;
current[1] = 74;
current[2] = 8;
current[3] = 105;
matlab.Execute("cbcw");
object result = null;
matlab.Feval("cbcw", 1, out result, current);
object[] res = result as object[];
Console.WriteLine(res[0]);
Console.ReadLine();
}
正在运行的程序是打开一个 matlab 命令行并将以下内容写入控制台:
System.Double[,]
我想在不打开 matlab 的情况下将数字写入控制台,因为这最终将成为没有 matlab 的计算机的独立进程。
【问题讨论】: