I am making a Java program that must call some matlab functions. I have received some simple test programs to play with so I can learn how it all works.
My problem is that one of the matlab test programs returns two parameters, but in my Java program I only see/get one.
Here is the matlab code:
function [out1,out2]=test_Java5(in1,in2)%
% [out1,out2]=test_Java5(in1,in2)
%% out1='ABC';
% out2='DEF';
%disp(in1);disp('');disp(in2);out1='ABC';out2='DEF';end
Here is the Java method that calls matlab and prints output:
private static void testJava5(Testfunctions test) { MWCharArray a = null; MWCharArray b = null; Object[] result = null; try { System.out.println("Starting testJava5"); a = new MWCharArray("Mary Smith"); b = new MWCharArray("John Doe"); result = test.test_Java5(1, a, b); System.out.println("Results=" + result.length); for (int i=0; i < result.length; i++) { System.out.println("Type=" + result[i].getClass() + ", Result=" + result[i]); } System.out.println("Finished testJava5"); } catch (Throwable t) { t.printStackTrace(); } finally { a.dispose(); b.dispose(); MWArray.disposeArray(result); } }
Here is the output from my Java program:
Starting testJava5Mary SmithJohn DoeResults=1Type=class com.mathworks.toolbox.javabuilder.MWCharArray, Result=ABCFinished testJava5
As you can see from the output, matlab prints out the two input parameters given to it, but the Java program only receive one parameter back as a MWCharArray (string).
I would have expected that my result array contained two records, or that result[0] was of type MWArray which contained the two MWCharArrays. But apperently not.
What am I doing wrong here?
PS: I know that I can use a struct instead, but we have a very complex set of input and outputs that would make it easier if it was separated.
Best Answer