PDA

View Full Version : سوال: فراخوانی توابع متلب در سی شارپ



milad rezae
سه شنبه 13 بهمن 1394, 15:16 عصر
سلام و خسته نباشید
من تابعی به صورت زیر در متلب ایجاد کردم :

function max = mymax(n1,n2,n3,n4,n5)
%This function calculates the maximum of the
% five numbers given as input
max = n1;
if(n2 > max)
max = n2;
end
if(n3 > max)
max = n3;
end
if(n4 > max)
max = n4;
end
if(n5 > max)
max = n5;
end
end
سپس از متلب برای استفاده از این تابع در سی شارپ یک dll به نام Mymax دریافت کردم که آن را به پروژه سی شارپ ویندوز فرم reference کردم. کد سی شارپ من به صورت زیر می‏باشد :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mymax;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;


namespace Mymax_with_Matlab
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


private void button1_Click(object sender, EventArgs e)
{
Mymax.Mymax c1 = new Mymax.Mymax();
int a = Convert.ToInt32(c1.mymax(1, '2', '3', '4', '5'));
}
}
}

هنگام اجرا Error زیر را دریافت می‏کنم که بشدت گیج شده ام... خواهشن به من کمک کنید ممنون :افسرده::لبخندساده:

... MWMCR::EvaluateFunction error ...
Not enough input arguments.
Errorin=> mymax.m at line 14.

...Matlab M-code StackTrace...
at
file C:\Users\milad\AppData\Local\Temp\milad\mcrCache8. 1\Mymax_0\Matlab Examples\mymax.m, name mymax, line 14