|
Matlab与其他语言和软件的接口问题
>************************************************************************<
=================================== - [返回]
1).如何在Matlab中读取Excel的xls数据文件?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22. BigGreen/MathTools#
使用xlsread()函数,或者使用excel的ActiveX接口来进行更复杂的操作,
参见:
<A TARGET=_blank HREF="http://www.mathworks.com/support/solutions/data/25179.shtml">http://www.mathworks.com/support/solutions/data/25179.shtml</A>
=================================== - [返回]
2).如何在Excel中嵌入Matlab?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
如果你的Matlab安装有ExcelLink,它可以实现Excel与Matlab直接的数
据交换,可以在Excel中直接调用matlab的函数,进行绘图或者数据处理。
不过如果没有安装ExcelLink,你仍然可以使用Matlab的ActiveX接口来
调用matlab,下面是一个Excel宏函数,作为例子:
#Brett Shoelson(bshoelson@cox.rr.com),2001/11/01,comp.soft-sys.matlab#
Sub CallMatlab()
' Dimension variables
Dim MatLab As Object
Dim Result
Dim Invals(3, 4) As Double
Dim MImag() As Double
Dim i, j As Integer
' Invoke Matlab
Set MatLab = CreateObject("Matlab.Application")
' Read Invals from current spreadsheet
' (Assume Invals stored in B3:E5)
For i = 0 To 2
For j = 0 To 3
Invals(i, j) = ActiveSheet.Range(Cells(i+3,j+2),
Cells(i+3,j+2)).Value
Next j
Next i
' Send Invals to Matlab
Call MatLab.PutFullMatrix("a", "base", Invals, MImag)
' Send instructions to Matlab
Result = MatLab.Execute("b=a.^2;")
' Retrieve Result
Call MatLab.GetFullMatrix("b", "base", Invals, MImag)
' Store Result in B8:E10
ActiveSheet.Range("B8:E10").Value = Invals
End Sub
=================================== - [返回]
3).mcc,mex,mbuild都是作什么用的?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
这个问题我一直都不是很清楚,看过compiler的PDF帮助之后,知道个
大概,也不知道说得对不对:
mcc(生成c/cpp文件)-----m--mex------ mex/dll
|---x--mbuild-----C/C++ compiler----独立执行的程序
mex文件是一种编译后的动态连接文件,需要在matlab中执行,优点
是执行速度比m文件快,而且如果你不想提供m文件源码,可以使用
编译后的mex/dll文件。
mbuild通过调用外部的c/c++编译器,把mcc翻译成的c/c++源码
与matlab的c/c++数学库、图形库链接,得到独立执行的可执行程序。
=================================== - [返回]
4).用mcc生成的独立执行exe文件怎么发布?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
使用matlab自己提供的mglinstaller,路径在
\extern\lib\win32\mglinstaller.exe
参考C++ Math Lib,C++ Graphic Lib,Compiler的PDF帮助中都有关于打包
和安装的详细介绍。
=================================== - [返回]
5).如何在VC中调用Matlab engine?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
matlab提供了ActiveX接口,你可以功过调用接口的底层函数来实现在
你的C++/VB/Delphi程序中启动、执行matlab并交换数据,但matlab提
供了一个对这些底层ActiveX接口函数的封装,叫作maltab engine,在
C语言中调用engine的例子参见:
<A TARGET=_blank HREF="http://www.mathworks.com/access/helpdesk/help/techdoc/">http://www.mathworks.com/access/helpdesk/help/techdoc/</A>
matlab_external/ch06eng4.shtml#25603
或者
<A TARGET=_blank HREF="http://www.matlab-world.com/matlab_and_c.htm">http://www.matlab-world.com/matlab_and_c.htm</A>#VC_ml
<A TARGET=_blank HREF="http://bbs.dartmouth.edu/cgi-bin/bbscon?">http://bbs.dartmouth.edu/cgi-bin/bbscon?</A>
board=MathTools&file=M.1022120287.A&num=23
可以使用engEvalString直接在matlab中执行语句,也可以
用mxCreateDoubleMatrix, mxDestroyArray,engPutArray,engGetArray等函数
创建矩阵和数据交换。
具体参见:
<A TARGET=_blank HREF="http://www.mathworks.com/access/helpdesk/help/techdoc/">http://www.mathworks.com/access/helpdesk/help/techdoc/</A>
matlab_external/matlab_external.shtml
=================================== - [返回]
6).如何在Matlab调用外部的c/c++/fortran函数?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
在用matlab的mex把外部c/for程序编译成mex/dll之前,你需要在你的外
部函数的源码中添加一个mexFunction(),具体书写格式和例子参见
<A TARGET=_blank HREF="http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/apiext.pdf">http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/apiext.pdf</A>
=================================== - [返回]
7).如何在Delphi中调用Matlab(ActiveX)?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
从这个地址下载例子:
<A TARGET=_blank HREF="http://www.djpate.freeserve.co.uk/Matlab.htm">http://www.djpate.freeserve.co.uk/Matlab.htm</A>
还有一种方法是利用DelphiMEX,下载地址:
<A TARGET=_blank HREF="http://Radio-BIP.qc.ca/DelphiMEX/DelphiMEX.html">http://Radio-BIP.qc.ca/DelphiMEX/DelphiMEX.html</A>
下面是把Alex Conradie的例子中选了一些主要的语句:
var
V : Variant;
MReal : OleVariant;
MImage : OleVariant;
begin
i,j : integer;
MReal := VarArrayCreate([0, 1, 0, 3], varDouble);
MImage := VarArrayCreate([0,0,0,0], varDouble);
V := CreateOLEObject('Matlab.Application');
V.Execute('a=[1 2 3 4; 5 6 7 8]');
V.GetFullMatrix('a','base',VarArrayRef(MReal),VararrayRef(MImage));
for i := 0 to 1 do
for j := 0 to 3 do
Stringgrid1.Cells[j,i] := MReal[i,j];
V.Execute('peaks');
MReal := VarArrayCreate([0, 1, 0, 3], varDouble);
MImage := VarArrayCreate([0,0,0,0], varDouble);
for i := 0 to 1 do
for j := 0 to 3 do
MReal[i,j] := i+4;
V.PutFullmatrix('b','base',VarArrayRef(MReal),VararrayRef(MImage));
end
=================================== - [返回]
8).如何在C++ Builder中调用Matlab(ActiveX)?
:# Serge Kanilo (skanilo@hotmail.com), 2000/08/01. comp.soft-sys.matlab #
I once called a Matlab function out of Borland Builder 4.0.
I used an automation
#include
...
Variant matlab;
matlab = Variant::CreateObject("Matlab.Application");
Procedure exec("Execute");
matlab.Exec(exec << "calc");
…
=================================== - [返回]
9).如何在VB中调用Matlab(ActiveX)?
:# Taras Chaban (taras@camcontrol.co.uk), 1999/03/09.
comp.soft-sys.matlab #
Hi,
You can call MATLAB from VB using ActiveX interface.
A simple example could be:
Sub tot1()
Dim MatLab As Object
Dim Result As String
Dim MReal(1, 3) As Double
Dim MImag() As Double
Set MatLab = CreateObject("MatLab.Application")
Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8;]")
Call MatLab.GetFullMatrix("a", "base", MReal, MImag)
End Sub
=================================== - [返回]
10).如何在VC中调用Matlab编译的cpp文件
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
参见
<A TARGET=_blank HREF="http://www.mathworks.com/support/solutions/data/21291.shtml">http://www.mathworks.com/support/solutions/data/21291.shtml</A>
中文地址请大家推荐
=================================== - [返回]
11).如何在VC中调用mcc编译的dll?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
参见
<A TARGET=_blank HREF="http://www.mathworks.com/support/solutions/data/28621.shtml">http://www.mathworks.com/support/solutions/data/28621.shtml</A>
中文地址请大家推荐
=================================== - [返回]
12).如何在Matlab中调用其他软件的ActiveX接口?
:#FangQ(Qianqian.Fang@dartmouth.edu), 2002/6/22.BigGreen/MathTools#
在Matlab中参见actxserver和actxcontrol的帮助
这里是一个在matlab中操纵PowerPoint的例子:
<A TARGET=_blank HREF="http://groups.google.com/groups?">http://groups.google.com/groups?</A>
selm=370E09E2.275EF5E8%40mail.northgrum.com&output=gplain
中文地址请大家推荐
|
|