Thread Subject: Calling Matlab from Java

Subject: Calling Matlab from Java

From: Stephan Larws

Date: 9 Sep, 2009 09:45:03

Message: 1 of 7

Hi,

I'm trying to call Matlab functions from java via the Matlab Engine. It works fine as long as there are no Matlab GUI elements involved. But I need to call scripts which create a GUI and run then in their own Matlab window. Does anyone know if there are limitations to the type of scripts called via the matlab engine? Thanks for all your help :)

Subject: Calling Matlab from Java

From: Rune Allnor

Date: 9 Sep, 2009 10:02:28

Message: 2 of 7

On 9 Sep, 11:45, "Stephan Larws" <stephan.la...@iav.de> wrote:
> Hi,
>
> I'm trying to call Matlab functions from java via the Matlab Engine. It works fine as long as there are no Matlab GUI elements involved. But I need to call scripts which create a GUI and run then in their own Matlab window. Does anyone know if there are limitations to the type of scripts called via the matlab engine? Thanks for all your help :)

Don't know if there are limitations, but there is at least
ample opportunity for trouble if you start mixing a matlab
GUI engine with an already existing GUI.

Use java for the GUI and leave the matlab engine to deal
with computations.

Rune

Subject: Calling Matlab from Java

From: Stephan Larws

Date: 10 Sep, 2009 06:22:01

Message: 3 of 7

Rune Allnor <allnor@tele.ntnu.no> wrote in message <25d774c7-0b3a-4822-88c4-82269abb04f6@x38g2000yqb.googlegroups.com>...
> Don't know if there are limitations, but there is at least
> ample opportunity for trouble if you start mixing a matlab
> GUI engine with an already existing GUI.
>
> Use java for the GUI and leave the matlab engine to deal
> with computations.
>
> Rune

Hi Rune,

thank you for your fast response. Normally I would do everything like you said, but my problem is, that these matlab scripts are already existing and they include the GUI and quite a bit of other code so rewriting everything would be my last resort. And unfortunately GUI code and program code are really tangled up :(. It seems that only calling GUIs that were made with GUIDE are problematic. It would be nice to know if anyone has a similar problem.

Subject: Calling Matlab from Java

From: Stephan Larws

Date: 10 Sep, 2009 07:07:01

Message: 4 of 7

"Stephan Larws" <stephan.larws@iav.de> wrote in message <h8a5u9$mcm$1@fred.mathworks.com>...
> Rune Allnor <allnor@tele.ntnu.no> wrote in message <25d774c7-0b3a-4822-88c4-82269abb04f6@x38g2000yqb.googlegroups.com>...
> > Don't know if there are limitations, but there is at least
> > ample opportunity for trouble if you start mixing a matlab
> > GUI engine with an already existing GUI.
> >
> > Use java for the GUI and leave the matlab engine to deal
> > with computations.
> >
> > Rune
>
> Hi Rune,
>
> thank you for your fast response. Normally I would do everything like you said, but my problem is, that these matlab scripts are already existing and they include the GUI and quite a bit of other code so rewriting everything would be my last resort. And unfortunately GUI code and program code are really tangled up :(. It seems that only calling GUIs that were made with GUIDE are problematic. It would be nice to know if anyone has a similar problem.

Don't know if anybody is interested, but I think I found a solution and it has nothing to do with the GUIs. Once I started the engine with engOpen() the pwd was the matlab root directory and that caused trouble. So changing the pwd made all my problems go away ;).

Subject: Calling Matlab from Java

From: tristram.scott@ntlworld.com (Tristram Scott)

Date: 10 Sep, 2009 11:10:58

Message: 5 of 7

Stephan Larws <stephan.larws@iav.de> wrote:
> Rune Allnor <allnor@tele.ntnu.no> wrote in message <25d774c7-0b3a-4822-88c4-82269abb04f6@x38g2000yqb.googlegroups.com>...
>> Don't know if there are limitations, but there is at least
>> ample opportunity for trouble if you start mixing a matlab
>> GUI engine with an already existing GUI.
>>
>> Use java for the GUI and leave the matlab engine to deal
>> with computations.
>>
>> Rune
>
> Hi Rune,
>
> thank you for your fast response. Normally I would do everything like you
> said, but my problem is, that these matlab scripts are already existing and
> they include the GUI and quite a bit of other code so rewriting everything
> would be my last resort. And unfortunately GUI code and program code are
> really tangled up :(. It seems that only calling GUIs that were made with
> GUIDE are problematic. It would be nice to know if anyone has a similar
> problem.

As you say, your problem is that the code for the GUI is tangled up with
the code for the computations. Even if you have already found a way around
this, I would urge you to spend half an hour separating the gui code from
the funcional code. It makes life simpler for everyone.

If you do choose to use Guide to create your GUIs, make a point of adding
as few lines of code as possible to the automatically generated code that
Guide produces. Keep you own code away from what Guide produces, and that
way you can keep Guide away from your code. There have been many postings
on this newsgroup relating sad stories of Guide not working well across
different MATLAB releases.

--
Dr Tristram J. Scott
Energy Consultant

Subject: Calling Matlab from Java

From: Rune Allnor

Date: 10 Sep, 2009 12:49:34

Message: 6 of 7

On 10 Sep, 08:22, "Stephan Larws" <stephan.la...@iav.de> wrote:
> Rune Allnor <all...@tele.ntnu.no> wrote in message <25d774c7-0b3a-4822-88c4-82269abb0...@x38g2000yqb.googlegroups.com>...
> > Don't know if there are limitations, but there is at least
> > ample opportunity for trouble if you start mixing a matlab
> > GUI engine with an already existing GUI.
>
> > Use java for the GUI and leave the matlab engine to deal
> > with computations.
>
> > Rune
>
> Hi Rune,
>
> thank you for your fast response. Normally I would do everything like you said, but my problem is, that these matlab scripts are already existing and they include the GUI and quite a bit of other code so rewriting everything would be my last resort.

Well, if your code is already a mess, it will not
become less of a mess if you postpone straightening
it out. There are only two valid reasons for you
*not* reworking the code *now*:

- The code will never be used again.
- Your last day on the project was today.

If there is even the slightest chance somebody will
use the code in the future, you are doing everybody
a favour by clearing it up now.

Syre, it will be a lot of work that is 'invisible'
to your boss, but you (or whoever else will maintain
the code in the future) will save immense amounts
of both time and trouble.

Rune

Subject: Calling Matlab from Java

From: Pontus H?rling

Date: 23 Sep, 2009 09:58:03

Message: 7 of 7

Hello, I would like to call Matlab code not only matlab functions but code I have written myself) from a stand-alone Java program. You say you do it via the Matlab engine, but can this be done from Java? Is it not only from C/C++ or Fortran, so sys the manual...? Do you go in 2 steps via JNI (Java Native Interface) in C which has to be mex.ed or something?

Best

Pontus H?rling

"Stephan Larws" <stephan.larws@iav.de> wrote in message <h87tev$18l$1@fred.mathworks.com>...
> Hi,
>
> I'm trying to call Matlab functions from java via the Matlab Engine. It works fine as long as there are no Matlab GUI elements involved. But I need to call scripts which create a GUI and run then in their own Matlab window. Does anyone know if there are limitations to the type of scripts called via the matlab engine? Thanks for all your help :)

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
java matlab gui Stephan Larws 9 Sep, 2009 05:49:04
rssFeed for this Thread

Contact us at files@mathworks.com