77范文网 - 专业文章范例文档资料分享平台

matlab与vc混编(3)

来源:网络收集 时间:2019-02-17 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

4.50\\License\\ 下面添加一个键,键名默认,键值为FREE-4.5-1193046-80295111 你如 果删除

它,再次启动matcom的时候,就会再次询问口令。 不过好在如果通过这个口令之后,程 序发

布时就不再有限制了,也 就是在这个注册后的系统中编译的程序,发布时就不用代一个 注册 文件了

3.3 用Matcom翻译m文件

直接调适M文件:在主界面上打开.m文件的主文件,在菜单中选择compile to exe or d

ll 就可以了,你也可以设置断点后,就可以查看变量的值,这些将在主窗口 的一侧出 现,双

击就可得到其当前值。 编译后的cpp、exe、dll文件都在matcom 当前工作目录下,如果 是de

bug模式,就在 dubug目录下找,否则就在Release目录下找。

3.4 在CB中C++与Matlab语言混编

这种方法是我最喜欢的方法,因为这样不但可以发挥matcom强大的数学计算功能, 还可

以结合可视化编译环境来进行界面开发,可以制作完整的应用计算软件, 交付用户使用 。 我

所用的可视IDE是Inprise公司的C++Builder 3.0/4.0,matcom版本为4.0/4.5, 注意,在 CB4.

0上只能使用matcom4.5版本。 在进行编程之前你需要作如下准备工作

1.选择菜单New\\Console Wizard\\Console Exe,建立一个Win32位DOS程序 2.将matc om\\

lib\\matlib.h拷贝到CB\\include目录下 将matcom\\lib\\v4500b.lib拷贝到CB\\lib目录下 3.选

择菜单Project\\Add to project\\选择lib\\v4500.lib

于是程序变为 #pragma hdrstop #include #include \#include \

//--------------------------------------------------------------------------- US

ELIB(\

//--------------------------------------------------------------------------- #pragma argsused int main(int argc, char **argv) { /*****************************************/ // Please Write Your Code Here */ /*****************************************/

return 0; return 0;能使用matcom4.5版本。 }

3.选择菜单Project\\Add to Reportaries\\ 将该工程存为Project中的一个模板。 3.选

择菜单Project\\Add to Reportaries\\ 将该工程存为Project中的一个模板。 OK,现在可 以进

行你所需要的工作了。 用菜单你存为的模板建立一个新的工程,在代码段写 dMm(a); //def

ine a Matrix class a=zeros(3); //Let the matrix be a 3*3 zero matrix disp(a); //D

isplay the matrix 运行一下看看,程序会打印出3*3的0零阵 稍微复杂一点的程序 dMm(a);

dMm(b);dMm(c); //声明三个矩阵 a=rand(3,2); //生成3*2随机阵 b=zeros(3,2); c=a+b; /

/矩阵相加 c(1,c_p)=a(2,c_p); //matlab中写为c(1,:)=a(2,:) c=ctranspose(c); // 矩阵转

置 disp(c);printf(\disp(a);printf(\getch(); c(colon(1,1,3))=a(colon(1

,2,5)); //matlab中写为c([1:1:3])=a([1:2:5]) disp(c); getch(); getch();

可以发现在matlab中常用的一些表示都可以在matcom中找到对应,并且同样 方便有 效。

再举一个绘图的例子,就用matcom自己带的例子吧 subplot(121.0);

//subplot(1,2,1) surf((CL(peaks(25.0)))); //surf(peaks(25)) subplot(122.0); //subplot(1,2,2) pcolor((CL(peaks(25.0)))); //pcolor(peaks(25)) colormap(TM(\

//colormap('copper') drawnow() //必须有这句,否则只画一个图出来 //这是我问他们的技术支持搞到的

可以看到基本上是一句对一句,没有什么多余的话。所以习惯编写 matlab程序的同志写matcom C的语句来也应该没有什么问题。 (但上面这个程序确实有问题,在mideva中编译后第二 个subplot 是可以正常画出来的,但在CB中编译就只画一个subplot乐,具体 画一个subplot 乐,具体原因希望大家讨论,我现在也在试),mideva 编译该语句的指令是

bcc32 文件名 -IC:\\MATCOM45\\lib -H=matlib.csm -v -a4 -5 -e EXEFLAGS= -WC DLLFLAGS= -WD

我想CB中可能要改option,大家试试看。 总的说来,决大多数的matlab的语句都可以轻 松移植到CB中来,所以就可以直接在 CB中写matlab程序了,只是大家要注意几个关键的函数 colon(xstart,xstep,xstop) == xstart:xstep:xstop (CL(A1),A2,A3....) ==

(A1,A2,A3,...)一个矩阵行,大多数 多参数输入函数都用到CL (BR(a1),a2,a3....) == (a1,a2,a3...)

TM(\string\== 'a string' TM将char *变为串矩阵 c_p == : 整行或整列 i_o == [out =fun(in)就写为fun(in, i_o, out) 其他的大家编几个程序就清楚了。

3.6 程序的发布

matcom可以用C编译器把.m文件编译为为stand_alone的程序,所以,基本上 不需要mat lab系统,但一些必要的dll文件还是需要的,这些dll在window\\system\\ 下面,(在4.5版本中)大概有ago4500.dll,v4500v.dll,opengl32.dll, glu32.dll等 四个文件 如果用的是4.0版本,发布时要把ago.dll,mlib4...dll(计不清楚了),opengl32.dll和 glu32.dll打到安装盘中,大概3M,然后在window目录安装一个名字叫mt_eval.txt的 文本文件,里面写1/1/1999-1/1/2010-64562264即可

附录:Matcom C数学库函数列表(部分)

这是一个丰富的数学库,约600个函数,包括sim()函数 -------------------------------------------------------------------------- 矩阵基础类 系统常数 特殊函数 异常处理函数 矩阵生成函数 操作系统资源函数 数值计算函数 数学函数 矩阵操作函数 矩阵属性函数 图形函数 颜色函数 用户介面函数 is*函数族 mex函数 字符串函数

字符串函数 类型转换函数

************************************************************************** >>> 矩阵基础类

************************************************************************** class Mm {

DLLI Mm();

DLLI Mm(int isc, int iss, int nonzeros, int nrows, int ncols, mt_matrix_types new_type=mt_double_matrix);

DLLI Mm(int isc, int iss, int nonzeros, int new_ndims, const int new_dims[max_ndims], mt_matrix_types new_type=mt_double_matrix);

DLLI Mm(i_o_t, const char* mname, int isglobal); DLLI Mm(const char* mname, int m, int n);

DLLI Mm(int aisc, cMm x, cMm y, cMm dim1, op_t op, int do_dim, Mm& minmax_b] idx); DLLI Mm(m_type src); DLLI Mm(cMm src);

DLLI Mm(cMm src, const char* mname); DLLI Mm(const Mc& src); DLLI Mm(cMr src, int err=1); DLLI ~Mm();

Mm RDLLI operator =(cMm src);

void DLLI deepcopy(cMm src, mt_matrix_types new_type=mt_uninit_matrix); void DLLI deepcopy(int isc, cMm src, mt_matrix_types new_type=mt_uninit_matrix); void DLLI deepcopy(int isc, int iss, cMm src, mt_matrix_types new_type=mt_uninit_matrix); int DLLI getreal(int force=0) const; int DLLI getcomplex(); void DLLI collapse();

inline int DLLI rows() const { return dims[0]; } inline int DLLI cols() const { return dims[1]; } int DLLI size() const;

int DLLI size() const;x, cMm y, cMm dim1, op_t op, int do_dim, Mm&minmax_ab] int DLLI size(int dim) const; int DLLI nsingleton() const; int DLLI vectordim() const; int DLLI length() const;

const char PDLLI getname() const { return self_name; } void DLLI setname(const char* new_name);

int DLLI isstr() const { return (flags.str!=0); } void DLLI setstr(int newd);

inline int DLLI issparse() const { return (flags.sparse!=0); } void DLLI setsparse(int sp);

inline int DLLI islogical() const { return (flags.logical!=0); } { return (flags.logical!=0); } void DLLI setlogical(int newd);

inline int DLLI isglobal() const { return (flags.global!=0); } inline int DLLI isstruct() const { return (fields!=NULL); } inline int RDLLI getndims() const { return (int&)ndims; } inline int PDLLI getdims() const { return (int*)dims; } inline M_types RDLLI getflags() { return flags; }

inline mt_matrix_types DLLI gettype() const { return flags.type; } inline int DLLI getnfields() const { return nfields; }

inline const char PPDLLI getfields() const { return fields; } inline int DLLI isc() const { return (pi!=NULL); } int do_dim, Mm& minmax_ab]

int DLLI issamename(const char *s) const { return s==self_name; } int DLLI dirty() const;

int DLLI getp() const { return p; } Mm DLLI safebr(int i0) const;

inline m_type PDLLI getpr(m_type*) const { return (m_type*)pr; } inline m_type PDLLI getpi(m_type*) const { return (m_type*)pi; } inline uint8 PDLLI getpr(uint8*) const { return (uint8*)pr; } inline uint8 PDLLI getpi(uint8*) const { return (uint8*)pi; } inline Mm PDLLI getpr(Mm*) const { return (Mm*)pr; } inline Mm PDLLI getpi(Mm*) const { return (Mm*)pi; }

inline m_type PDLLI getpr(m_type*,int i0) const { return i0-1+(m_type*)pr; } }

inline m_type PDLLI getpi(m_type*,int i0) const { return i0-1+(m_type*)pi; }

inline uint8 PDLLI getpr(uint8*,int i0) const { return i0-1+(uint8*)pr; }

inline uint8 PDLLI getpi(uint8*,int i0) const { return i0-1+(uint8*)pi; }

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库matlab与vc混编(3)在线全文阅读。

matlab与vc混编(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/478893.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: