Thread Subject: MATLAB as ActiveX object

Subject: MATLAB as ActiveX object

From: Aleksey Komarov

Date: 2 Dec, 2008 11:54:01

Message: 1 of 3

Please, help me to run some code in current MATLAB session, the following example on Visual Basic Script doesn't work:
Dim MatLab
Dim Result
Set MatLab = Getobject(,"Matlab.Application")
Result = MatLab.Execute("surf(peaks)")
Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8]")
Result = MatLab.Execute("b = a + a ")
msgbox Result

BUT the same code, which started new matlab kernel works fine:
....
Set MatLab = CreateObject("Matlab.Application")
Result = MatLab.Execute("surf(peaks)")
........

Please help!!!

Subject: MATLAB as ActiveX object

From: Ben Hinchliffe

Date: 3 Dec, 2008 00:12:01

Message: 2 of 3

Hi Aleksey,
I saw this same problem while developing a product called Inference for MATLAB (enables users to execute MATLAB files/code in Word & Excel). We didn't push hard for a workaround, but if you need a simple way to access the MATLAB API you can use Inference and access it through Word or Excel. www.InferenceForMATLAB.com
Good luck!
-Ben

"Aleksey Komarov" <abkomarov@gmail.com> wrote in message <gh37kp$5l3$1@fred.mathworks.com>...
> Please, help me to run some code in current MATLAB session, the following example on Visual Basic Script doesn't work:
> Dim MatLab
> Dim Result
> Set MatLab = Getobject(,"Matlab.Application")
> Result = MatLab.Execute("surf(peaks)")
> Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8]")
> Result = MatLab.Execute("b = a + a ")
> msgbox Result
>
> BUT the same code, which started new matlab kernel works fine:
> ....
> Set MatLab = CreateObject("Matlab.Application")
> Result = MatLab.Execute("surf(peaks)")
> ........
>
> Please help!!!

Subject: MATLAB as ActiveX object

From: rtServo

Date: 6 Dec, 2008 22:17:38

Message: 3 of 3

On Tue, 2 Dec 2008 11:54:01 +0000 (UTC), "Aleksey Komarov"
<abkomarov@gmail.com> wrote:

>Please, help me to run some code in current MATLAB session, the following example on Visual Basic Script doesn't work:
>Dim MatLab
>Dim Result
>Set MatLab = Getobject(,"Matlab.Application")
>Result = MatLab.Execute("surf(peaks)")
>Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8]")
>Result = MatLab.Execute("b = a + a ")
>msgbox Result
>
>BUT the same code, which started new matlab kernel works fine:
>....
>Set MatLab = CreateObject("Matlab.Application")
>Result = MatLab.Execute("surf(peaks)")
>........
>
>Please help!!!

What worked for me was first to start Matlab with the /automation
switch so that it acts as an ActiveX server. Then I used:

Set MatLab = GetObject("","Matlab.Application")

Note that if the Matlab object goes out of scope, Matlab will close.

-rt

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
object Ben Hinchliffe 2 Dec, 2008 19:15:12
matlab api Ben Hinchliffe 2 Dec, 2008 19:15:12
inference for m... Ben Hinchliffe 2 Dec, 2008 19:15:12
inference Ben Hinchliffe 2 Dec, 2008 19:15:12
comm Ben Hinchliffe 2 Dec, 2008 19:15:12
create object Ben Hinchliffe 2 Dec, 2008 19:15:12
application Ben Hinchliffe 2 Dec, 2008 19:15:12
visual basic Ben Hinchliffe 2 Dec, 2008 19:15:12
vb Ben Hinchliffe 2 Dec, 2008 19:15:12
active x Ben Hinchliffe 2 Dec, 2008 19:15:12
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com