• 大小: 92KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C#
  • 标签: C#  Matlab  COM  

资源简介

C#引用COM组件调用Matlab,可以实现图像嵌入C#,能操作Matlab实现大多数功能,本例子实现了显示正弦图,显示三维螺旋线图等5种操作。 本人习惯vb.net编程,从vb.net转过来,vb.net不需要引用即可 引用COM组件Matlab Application(Version 8.3) Type Library//根据自己安装的版本引用

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        //用来记录命令串
        string str1=““;
       
        MLApp.MLApp  matlab=new MLApp.MLApp();
        public Form1()
        {
            InitializeComponent();
        }
        private void ShowPic()//显示图片
        {
            PictureBox1.Image = Image.FromFile(“d:\\Test1.jpg“);
        }
        //延时程序
        public void delay(long t)//延时程序
        {
            long temp = Environment.TickCount;
            while (Environment.TickCount - temp < t)
            {
                Application.DoEvents();
            }
        }
        private void Form1_Load(object sender EventArgs e)
        {
            matlab.Visible = 0;
        }
        private void Form1_FormClosing(object sender System.Windows.Forms.FormClosingEventArgs e)
    {
   matlab.Quit();
   //退出
   matlab = null;
   //释放资源
     }

        private void Button1_Click(object sender EventArgs e)
        {
              PictureBox1.Image = null;
              delay(100) ;//这里必不可少
              str1 = “t=1:0.1:2*pi;y=sin(t);plot(ty)“;
              matlab.Execute(str1);
              matlab.Execute(“print( gcf ‘-djpeg‘ ‘d:\\Test1‘)“) ;//把图像保存到指定位置
              matlab.Execute(“close all“);//关闭所有窗口
              ShowPic(); //显示图片

        }

        private void Button2_Click(object sender EventArgs e)
        {
            PictureBox1.Image = null;
            delay(100);//这里必不可少
            str1 = “sale=[100 150 400 250];pie3(sale[0 0 1 0]{‘春季‘‘夏季‘‘秋季‘‘冬季‘})“;
            matlab.Execute(str1);
            matlab.Execute(“print( gcf ‘-djpeg‘ ‘d:\\Test1‘)“);//把图像保存到指定位置
            matlab.Execute(“close all“);//关闭所有窗口
            ShowPic(); //显示图片

        }

        private void Button3_Click(object sender EventArgs e)
        {
            PictureBox1.Image = null;
            delay(100);//这里必不可少
            str1 = “t=0:0.1:8*pi;plot3(sin(t)cos(t)t)“;
            matlab.Execute(str1);
            matlab.Execute(“print( gcf ‘-djpeg‘ ‘d:\\Test1‘)“);//把图像保存到指定位置
            matlab.Execute(“close all“);//关闭所有窗口
            ShowPic(); //显示图片

        }

        private void Button4_Click(object sender EventArgs e)
        {
            PictureBox1.Image = null;
            delay(100);//这里必不可少
            str1 = “k = 5;n = 2^k-1;[xyz] = sphere(n);c = hadamard(2^k);surf(xyzc);“;
            str1 = str1 + “colormap ([1 1 0; 0 1 1]);axis equal“;
            matlab.Execute(str1);
            matlab.Execute(“print( gcf ‘-djpeg‘ ‘d:\\Test1‘)“);//把图像保存到指定位置
            matlab.Execute(“close all“);//关闭所有窗口
            ShowPic(); //显示图片

        }

        private void Button5_Click(object sender EventArgs e)
        {

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      11264  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\bin\Debug\Csharp_matlab.exe

     文件      26112  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\bin\Debug\Csharp_matlab.pdb

     文件      14328  2015-08-12 10:57  Csharp_matlab\Csharp_matlab\bin\Debug\Csharp_matlab.vshost.exe

     文件        490  2015-03-27 14:34  Csharp_matlab\Csharp_matlab\bin\Debug\Csharp_matlab.vshost.exe.manifest

     文件       8704  2015-08-12 10:33  Csharp_matlab\Csharp_matlab\bin\Debug\Interop.MLApp.dll

     文件       9728  2015-08-12 10:32  Csharp_matlab\Csharp_matlab\bin\Debug\WindowsFormsApplication1.exe

     文件      26112  2015-08-12 10:32  Csharp_matlab\Csharp_matlab\bin\Debug\WindowsFormsApplication1.pdb

     文件      14328  2015-08-12 10:33  Csharp_matlab\Csharp_matlab\bin\Debug\WindowsFormsApplication1.vshost.exe

     文件        490  2015-03-27 14:34  Csharp_matlab\Csharp_matlab\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest

     文件      11264  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\bin\Release\Csharp_matlab.exe

     文件      22016  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\bin\Release\Csharp_matlab.pdb

     文件       8704  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\bin\Release\Interop.MLApp.dll

     文件       3689  2015-08-12 10:33  Csharp_matlab\Csharp_matlab\Csharp_matlab.csproj

     文件         74  2015-08-12 10:33  Csharp_matlab\Csharp_matlab\Csharp_matlab.csproj.user

     文件       3715  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\Form1.cs

     文件       5817  2015-08-12 10:40  Csharp_matlab\Csharp_matlab\Form1.Designer.cs

     文件       5814  2015-08-12 10:40  Csharp_matlab\Csharp_matlab\Form1.resx

     文件       1196  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\obj\Debug\Csharp_matlab.csproj.FileListAbsolute.txt

     文件        847  2015-08-12 10:40  Csharp_matlab\Csharp_matlab\obj\Debug\Csharp_matlab.csproj.GenerateResource.Cache

     文件        520  2015-08-12 10:33  Csharp_matlab\Csharp_matlab\obj\Debug\Csharp_matlab.csproj.ResolveComReference.cache

     文件      11264  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\obj\Debug\Csharp_matlab.exe

     文件      26112  2015-08-12 10:42  Csharp_matlab\Csharp_matlab\obj\Debug\Csharp_matlab.pdb

     文件       8704  2015-08-12 10:33  Csharp_matlab\Csharp_matlab\obj\Debug\Interop.MLApp.dll

     文件       1328  2015-08-12 10:33  Csharp_matlab\Csharp_matlab\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件        847  2015-08-12 10:32  Csharp_matlab\Csharp_matlab\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache

     文件        520  2015-08-12 10:26  Csharp_matlab\Csharp_matlab\obj\Debug\WindowsFormsApplication1.csproj.ResolveComReference.cache

     文件       9728  2015-08-12 10:32  Csharp_matlab\Csharp_matlab\obj\Debug\WindowsFormsApplication1.exe

     文件        180  2015-08-12 10:40  Csharp_matlab\Csharp_matlab\obj\Debug\WindowsFormsApplication1.Form1.resources

     文件      26112  2015-08-12 10:32  Csharp_matlab\Csharp_matlab\obj\Debug\WindowsFormsApplication1.pdb

     文件        180  2015-08-12 10:36  Csharp_matlab\Csharp_matlab\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources

............此处省略30个文件信息

评论

共有 条评论