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.
Page Index Toggle Pages: 1
Mmmmatlab? (Read 2574 times)
Mmmmatlab?
Jul 12th, 2006, 6:05pm
 
I'm new to Matlab, old to Processing. Does anyone know how to integrate the two? I read in the help file for Matlab that it can integrate java, and I'll bet that can include Processing. I'm wanting to visualize some data nonrealtime, i.e. postprocess the raw numbers into pretty pictures. I guess I could do it by writing data to disk then rereading it, but that isn't my favorite solution. I want them integrated. I want to be able to type, prettyize_data(); and have Matlab prettyize it. Any ideas? Any experience with this?

Thanks,
Josh
Re: Mmmmatlab?
Reply #1 - Jul 13th, 2006, 12:40am
 
I did it the other way 'round, that is sending data from matlab to processing for plotting. Did it by starting the  processing applet from within matlab and feeding the matlab data into processing by a function call...

I'll just post it, hope it helps solving your problem.

THE MATLAB part:
Code:

function process()
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import processing.core.*;
import plotMatlab.*;
% create window in which applet will execute
applicationWindow = JFrame( 'An appl
et running as an application' );
width = 800;
height = 600;
% create one applet instance
appletObject = plotMatlab;

% call applet's init and start methods
appletObject.init;
appletObject.start;

% attach applet to center of window
applicationWindow.getContentPane.add( appletObject );

% set the window's size
applicationWindow.setSize( width, height );

% showing the window causes all GUI components
% attached to the window to be painted
applicationWindow.show;
setData(appletObject, 400+randn(10000,1)*80, 300+randn(10000,1)*60, rand(10000,1)*220, ones(10000,1)*80);


THE PROCESSING PART (plotMatlab.pde):

Quote:
float[] dataX, dataY, dataZ, dataCol, dataAlpha;
void setup(){  
 size(800,600,P3D);
 background(255);  
 println("P5: init");
}

void draw(){
 if (dataX!=null){
   plotData();
 }
}

void setData(float[] dataX, float[] dataY, float[] dataCol, float[] dataAlpha){
 this.dataX = dataX;
 this.dataY = dataY;
 this.dataCol = dataCol;
 this.dataAlpha = dataAlpha;
 println("P5: data set");
}

void plotData(){  
 background(255);  
 colorMode(HSB);
 for (int i=0; i<dataX.length;i++){  
   stroke(dataCol[i],220,220, dataAlpha[i]);
   point(dataX[i], dataY[i]);    
 }  
}




Think it's pretty straightforward.
To make matlab actually see your applet and the processing core.jar you have to add them via javaclasspath, but you might have figured that out by yourself through a search in matlab's excellent doc...

Regards,
postpop.
Re: Mmmmatlab?
Reply #2 - Sep 26th, 2009, 10:02am
 
Hi im trying your method and getting an error.  Im not clear on how matlab is meant to import .pde files as classes and call them.
Code:

>> javaaddpath('/media/DATA/Workspace/sketchbook/keyPressDATA');
>> import plotMatlab.*;

>> appletObject = plotMatlab
??? Undefined function or variable 'plotMatlab'.

>> ls
plotMatlab.pde process.m process.m~
Re: Mmmmatlab?
Reply #3 - Sep 26th, 2009, 10:05am
 
I don't know Matlab, but what postpop meant is that you export the sketch in the form of an applet and you use the generated .jar files in Matlab.
Page Index Toggle Pages: 1