Matlab vs C#

来源:互联网 发布:网站排名优化查询 编辑:程序博客网 时间:2024/05/29 12:46

Matlab vs C#


注意:空项目创建 C# project时,必须将所需 cs 文件 -> 添加 -> 解决方案 之中

否则会报错: “  不包含适合于入口点的静态“Main”方法 ”


C#与MATLAB互联互通  参考  Mathwork 文档

要添加 matlab 引用


using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace CSharpMatlabTest1{    public partial class Form1 : Form    {        private MLApp.MLApp matlab;        public Form1()        {            InitializeComponent();            matlab = new MLApp.MLApp();         }        private void btnStart_Click(object sender, EventArgs e)        {            //显示正弦图             //最小化matlab命令窗口             matlab.MinimizeCommandWindow();            string strMatLab = "t=2:0.2:4*pi;y=sin(t);plot(t,y)";            //最小化matlab命令窗口             matlab.Execute(strMatLab);               //生成一个JPG的图形c:\Test1.jpg             matlab.Execute("print( gcf, '-djpeg', 'c:\\Test1')");            //退出matlab,释放资源             matlab.Quit();            //显示在图片框 sizeMode 选择为 stretchImage             picMatlab.Image = new Bitmap("c:\\Test1.jpg");        }        private void btnPie_Click(object sender, EventArgs e)        {            //饼图             string strMatLab = "sale=[100 400 150 250 500];pie3(sale,[0 0 1 0 0],{'公司A','公司B','公司C','公司D','公司E'})" ;            matlab.Execute(strMatLab);        }        private void btnHelix_Click(object sender, EventArgs e)        {            //三维螺旋线图            string strMatLab = "t=0:0.2:4*pi;plot3(sin(t),cos(t),t)" ;            matlab.Execute(strMatLab);        }        private void btnWave_Click(object sender, EventArgs e)        {            //立体波浪图             string strMatLab = "[X,Y,Z] = peaks(20);surfc(X,Y,Z);colormap hsv;axis ([-2 4 -6 8 -10 6])" ;            matlab.Execute(strMatLab);        }    }}


0 0
原创粉丝点击