資源簡介
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?????????????{
????????????????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個文件信息
評論
共有 條評論