MATLAB与c#混合编程教程 (2).doc
上传人:qw****27 上传时间:2024-09-12 格式:DOC 页数:6 大小:151KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

MATLAB与c#混合编程教程 (2).doc

MATLAB与c#混合编程教程(2).doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

MATLAB与c#混合编程教程(MATLAB采用2010b,一切叙述以文字为准,图片可能不是很准确)kalman滤波在c#中实现首先在MATLAB中编写m文件kalmanfilter.mfunctionoutput=kalmanfilter(Y)[m,n]=size(Y);ifm~=1enda=1;w=randn(1,n);V=randn(1,n);q1=std(V);Rvv=q1.^2;q3=std(w);Rww=q3.^2;c=1;x(1)=0;p(1)=100;fort=2:np1(t)=a.^2*p(t-1)+0.05*Rww;b(t)=c*p1(t)/(c.^2*p1(t)+Rvv);x(t)=a*x(t-1)+b(t)*(Y(t)-a*c*x(t-1));p(t)=p1(t)-c*b(t)*p1(t);end用MATLAB的deploytool工具箱键入deploytool打开如下界面更改名字kalmanfilter.prj更改location为你想要的文件夹在target选项中选择.NETAssembly点okMATLAB右侧界面如图点击addclass默认名class1点击addfile把刚才编写的kalmanfilter文件添加进去然后点击build然后打开vs2010新建一个wpf文件界面粗略设计如下【在这之前还应编写个画图的文件用MATLAB编写plota.m文件functionplota(a,b)plot(a);holdonplot(b,'r');legend('原始','滤波后');xlabel('序号');ylabel('数值');Title('kalmanfilter');然后用deploytool同样的方法(name为plota,class1)】双击开始按钮(button1)弹出页面开始编辑下面编写c#文件usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Navigation;usingSystem.Windows.Shapes;usingMathWorks.MATLAB.NET.Arrays;usingMathWorks.MATLAB.NET.Utility;usingkalmanfilter;namespaceWpfApplication5{///<summary>///MainWindow.xaml的Ì?交?互£¤逻?辑-///</summary>publicpartialclassMainWindow:Window{publicMainWindow(){InitializeComponent();}privatevoidbutton1_Click_1(objectsender,RoutedEventArgse){stringstr="";string[]v=newstring[textBox1.Text.Length];intj=0;char[]char1=textBox1.Text.ToCharArray();string[]d=newstring[textBox1.Text.Length];intu=0;for(inti=0;i<textBox1.Text.Length;i++){if(char1[i]!='')str=str+char1[i];else{v[j]=str;str="";j++;}intn=0;for(intm=0;m<textBox1.Text.Length;m++){if(v[m]!=""&&v[m]!=null){d[n]=v[m];n++;}}u=n;}MWNumericArrayb=newMWNumericArray(MWArrayComplexity.Real,1,u);for(intq=1;q<=u;q++){b[q]=Convert.ToDouble(d[q-1