Can not PLOT through calling Matlab function in Java programming?

2 views (last 30 days)
Matlab version: R2012a Java IDE: Eclipse Indigo (Java SE 7) I have a Matlab function defined in a .m file, basically it returns an average value (it works in Java) and plot on a Matlab form:
function ave=myaverage(x, N)
sizex=size(x);
sizeN=size(N);
if sizex(2)~=sizeN(2)
disp('Error: x and N must have dimensions of the same number.')
else
total=sum(N);
s=x.*N; %????
ave=sum(s)/total;
end
[a,b]=meshgrid(-4:0.1:4,-5:0.1:5);
plot3(a,b,a.^3+b.^3), grid on
disp('This is a test of the function.')
I use Eclipse Indigo as the Java IDE. The Java codes are like this:
import TestPrj.MyAverageClass;
import com.mathworks.toolbox.javabuilder.MWArray; import com.mathworks.toolbox.javabuilder.MWClassID; import com.mathworks.toolbox.javabuilder.MWException; import com.mathworks.toolbox.javabuilder.MWNumericArray;
/** * @author Xiaoyu * */ public class UseMatlab {
/**
* @param args
*/
public static void main(String[] args) {
MWNumericArray a = null, b = null;
MyAverageClass mac = null;
try {
mac = new MyAverageClass();
a = new MWNumericArray(new int[] { 1, 2, 3 }, MWClassID.INT32);
b = new MWNumericArray(new int[] { 2, 3, 4 }, MWClassID.INT32);
Object[] cObject = mac.myaverage(1, a, b);
System.out.println(cObject[0].toString());
mac.waitForFigures();
} catch (MWException e) {
e.printStackTrace();
} finally {
MWArray.disposeArray(a);
MWArray.disposeArray(b);
b.dispose();
if (mac != null) {
mac.dispose();
}
}
}
}
The calculation part of the function returns a correct value. But the 'plot3(a,b,a.^3+b.^3)' only displays a Matlab form without the surface that should be drawn. My original purpose is to use this way to display my data processing result through hybriding Java and Matlab. Anyone can help me, please? BTW, I heard that it is a problem of the R2012a version of Matlab. Anyone can confirm this? Thanks!
p.s.The windows form displaying nothing: http://img507.imageshack.us/img507/7639/10241686.png

Answers (1)

Pinocchio
Pinocchio on 16 Sep 2013
Edited: Pinocchio on 16 Sep 2013
Hi Bruce,
I have met the same problem this afternoon. Now I fix it.
I also use Matlab 2012a 64 bit. When I used jdk-7u40-windows-x64 as my java compiler, I got the same problem as yours.
I read the documents of Matlab 2012a, it certified that it works on java 1.6. So I changed to jdk-6u45-windows-x64 as my java compiler, it works!!!
By the way, I use Windows 7 64 bit os, eclipse-java-kepler-R-win32-x86_64, Matlab 2012a 64 bits, jdk-6u45-windows-x64.
Wish you also succeed.
Best, Pinocchio

Categories

Find more on Java Package Integration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!