We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing <-> Matlab
Page Index Toggle Pages: 1
Processing <-> Matlab (Read 4527 times)
Processing <-> Matlab
Dec 11th, 2008, 9:54pm
 
Hi,
I am trying to make a processing application run by matlab and it seems to work but now that I try to draw things I get the following error:

> In javaclasspath>local_validate_dynamic_path at 247
 In javaclasspath>local_javapath at 157
 In javaclasspath at 102
 In javaaddpath at 68
 In processing at 1
??? Java exception occurred:
java.lang.RuntimeException: You need to use "Import Library" to add processing.core.PGraphicsJava2D to your
sketch.
at processing.core.PApplet.makeGraphics(PApplet.java:1176)
at processing.core.PApplet.init(PApplet.java:593)

Error in ==> processing at 18
appletObject.init;


what does that exactly mean? how can I do that import library?
Re: Processing <-> Matlab
Reply #1 - Jan 9th, 2009, 8:19am
 
hmm okay, seems nobody uses Matlab and Processing
If anybody does that and has a working program I'd like to know how they did it =)

thanks Smiley
Re: Processing <-> Matlab
Reply #2 - Feb 23rd, 2009, 11:33pm
 
Juxi;

I want to replace Matlab's elder plotting engine with a Processing solution...

Are you still there?
Re: Processing <-> Matlab
Reply #3 - Feb 24th, 2009, 12:21am
 
I did not succeed with mine, but I heard from another guy who was trying that and he managed to localize the error a bit better...

I am currently not using Matlab or Processing, but for me this would be killer feature, to enable visualization straight out of matlab!
Re: Processing <-> Matlab
Reply #4 - Feb 24th, 2009, 12:51am
 
Processing uses Java 1.4, Matlab 1.6. But that might be ok.

There are so many ways to go.  How about writing a function in Processing/Java and then calling it from Matlab?

I want to plot, so that would entail creating Java Arrays from inside Matlab and then using them from within Processing.

To do this I'd need a way to invoke Processing from within Matlab.  Second plan, talk to processing from Matlab.

The first hit I found is this:

http://dev.processing.org/bugs/show_bug.cgi?id=219

Are their other ways to talk to Processing from another app?
I'll keep looking.

A fallback plan would be to write a source code script from Matlab, make it into a jar and then pass it to Processing via the above method.  Ugh.

Juxi;  How did you get the message above?
Re: Processing <-> Matlab
Reply #5 - Feb 24th, 2009, 12:57am
 
Having some fun now,

I added all Processing jars to Matlab's static java path vis classpath.txt

>> processing.core.PGraphicsJava2D

gets me:

ans =

processing.core.PGraphicsJava2D@2b87514a


Re: Processing <-> Matlab
Reply #6 - Feb 24th, 2009, 1:19am
 
Kind of like dancing a jig I don't understand
to music that I can't quite feel with my fingertips
yet.  (Apologies for that, but it isn't the first time
I've done things the hard way Smiley  

I love Processing, and want to bind it to Matlab, and possibly R.

>> appl = processing.core.PApplet;
>> appl.init()
>> appl.size(100,100)

This goes down ok now, and Matlab tells me:

processing.core.PApplet[panel3,0,0,100x100,invalid,layout=java.awt.FlowLayout]

No window though, I think I need some non-PDE java to see how things are initialized properly.  Hmmm,  I bought Reas/Fry book, read the 1st half in an evening ...

Re: Processing <-> Matlab
Reply #7 - Feb 24th, 2009, 1:34am
 
yeah if I remember correctly I had the same problem that it would not generate a window and as soon as I tried to draw on the canvas the Graphics2D exception would be thrown..

sorry I am not much help right now since I work on another project (on another continent Wink) ...
but looks like you are getting somewhere Smiley
Re: Processing <-> Matlab
Reply #8 - Feb 24th, 2009, 1:42am
 
Thanks Juxi;

I can hit pretty hard today for a while yet, but tomorrow I must switch topics for a few days, so wish me luck

Okay,

http://dev.processing.org/reference/core/index.html

This was useful. It tells me that I need a rendering thread.  I will try to build processing from scratch to figure out the next step from the code.

If anyone thinks (or knows) I am on a dead-end drive, I'd really appreciate a smooth slap on the hand!



Re: Processing <-> Matlab
Reply #9 - Feb 24th, 2009, 2:24am
 
Build worked.  Nice code tree.

Had to install "Java 1.5.0_15 JDK"  Thank you
for that friendly error message telling me what
I needed to do.

CENTOS 5, 2.6.18-92.1.22.el5, 64bit build.

Not sure about this message:

/usr/share/themes/Clearlooks/gtk-2.0/gtkrc:60: Engine "clearlooks" is unsupported, ignoring

The menu rollover color seems to be white, I see that you put a lot of pieces in place to get that build at a production release.  THANK YOU.
Re: Processing <-> Matlab
Reply #10 - Feb 24th, 2009, 8:02am
 
ridley wrote on Feb 24th, 2009, 12:51am:
Processing uses Java 1.4, Matlab 1.6. But that might be ok.
Processing uses Java 1.6 for quite some time now. Just stuck at 1.4 syntax.
Re: Processing <-> Matlab
Reply #11 - Feb 24th, 2009, 6:07pm
 
Thanks PhiLho;

So lets review how far I got before I change contexts.

Able to get the classes PApplet and PGraphics2D instantiated inside Matlab, and can set some fields, etc.

This was accomplished by adding every jar file in the distribution to Matlab's static java path via the classpath.txt file.  

This is what I see:

appl = processing.core.PApplet;
appl.main('ump')  // 'ump' because I don't know what I should pass?

and try catch fails, and matlab exits right away.
Need to learn more about the Commander, too.

What I really need is a game plan.  Searching Matlab community reveals that many folk have successfully launched and operated Java applets from within Matlab, and the help stuff claims that java is a core competency and capability of Matlab.

So there are several approaches that I can see:

1) Write everything to a sketch file and just use the PDE.
2) Operate Processing via a java script wrapper that accepts matlab data and translates to the appropriate Processing java calls.
3) Somehow talk to the PDE from Matlab and operate it "remotely"
4) Use Commander
5) Enable direct calls to Processing Language inside Matlab M files.  This would require a prepend of something like processing.core.PApplet.size(100,100), or p.size(100,100) etc. to keep the namespace clear from Matlab's.

I am sure that there are others.  The discussion threads here on using Processing from the command line tells me that 2) above may not only be possible, but that my newness to Processing may be all that's stopping me.

But number five seems the real prize.  That would gain ease, and rapid adoption of use.  

Thanks for the help so far.  I'll respond, I just need to work on another system for a while...

R
Re: Processing and Matlab - Progress
Reply #12 - Feb 25th, 2009, 9:06pm
 
Cool!

Found out a first way to do development with Matlab/Processing.  Making Progress!

I have the static load working now, and got the Commander class to pop-up a dialog telling me that it needs JDK1.5 to run.  That is a pulse!!

The static path method I describe here, requires matlab be restarted to re-load the new processing jars after a build.  There is a dynamic java path mechanism that I need to figure out next

1) Checkout & Build processing via svn

2) Copy the stock-install classpath.txt from the matlab default directory, eg: "/usr/local/matlab75/toolbox/local/classpath.txt" to the top level processing/ directory. (Putting it here for convenience only)

3) Add absolute paths to all processing/ jar files within the build tree to the bottom of the classpath.txt file.  I "think" that matlab resolves paths via top down order so I tried to put libs, etc. last.  (I excluded mac & windows parts of the build as I am on linux, stayed tuned for more on this).

4) Now start matlab from this directory, and it will read your modified classpath.txt file instead of the default (because it is in the local directory).  If there are no complaints when matlab launches.  yer done!

Lessons so far:

- System.exit(0) from within processing; will cause matlab to exit.  Of course it does, silly.

- Printing from inside processing object routes back to the matlab prompt.

- One way to access and start PApplet from matlab command line:

>>appl = processing.core.PApplet;
>>appl.main('mp')

- Same for Commander:

>>cmdr = processing.app.Commander.main('--help')

It looks like I might get it working after all.  Still need a good code example for how to open and run a sketch from within my own Java wrapper ...

Cheers!!
Re: Processing <-> Matlab
Reply #13 - Feb 27th, 2009, 8:32pm
 
Ok, duh;

I apologize for my naive trumblings.  Trying to learn Processing, java, and matlab's use of java all at the same time!  (You should see me fly a plane)

Anyway,  I finally wound up here:

http://processing.org/reference/environment/platforms.html#linux

Rosetta stone, thank you.

cat processing, and now I see how it's done.

So I am switching the approach to extending PApplet to make a class that interfaces Matlab to Processing.  Er, actually that will be several classes.  The first class will be patterned after matlab's vanilla 'plot()' function.  The constructor will take the arrays and settings that are then used by the draw function to create the plot.

Note:

I still haven't started working on the dynamic path thing yet, but I did find out that the JDK jars can be inserted into matlab's classpath.txt file before the processing jars.
Re: Processing <-> Matlab
Reply #14 - Mar 24th, 2010, 6:11pm
 
I started to integrate processing with R. I get the same exception:

java.lang.RuntimeException: You need to use "Import Library" to add processing.core.PGraphicsJava2D to your
sketch.
at processing.core.PApplet.makeGraphics(PApplet.java:1176)
at processing.core.PApplet.init(PApplet.java:593)

I looked into the source code for PApplet and found out that the renderer class is loaded using a direct call to the class loader. It seems that the JNI interface used in R uses a custom class loader which clashes with the way the class is loaded in processing. That explains why the class can not be found even though it is imported. I guess Matlab has exactly the same problem. A quick and dirty fix is to change the PApplet code (method makeGraphics) to directly instantiate a renderer. I got a applet to work via R that way but there might be other parts of processing that also do not work and I am stuck with a single renderer.

-m
Page Index Toggle Pages: 1