FAQ

1. Forum discussion
Here – http://groups.google.com/group/jamal-project?pli=1

2. Multidimensional java arrays parsing

Due to some differences between Java and Matlab in the representation of multidimensional arrays, one needs to transform input Java array, that is represented in Matlab as cells into a Matlab array.

The example of computing the sum of a 2-D array is given below. Running this example requires test2dArray.m and javaCellArgs2Matlab.m files to be added to the Matlab path.

try {

	MatlabClient matlabClient = new MatlabClient(
		MatlabCaller.HOST_ADDRESS,
		MatlabCaller.MATLAB_EXECUTABLE_PATH);
	inArgs = new Object[1];
	inArgs[0] = new int[][] { { 1, 2, 3, 4 }, { 4, 5, 6, 7 },
			{ 7, 4, 7, 5 } };
	outputArgs = matlabClient.executeMatlabFunction("test2dArray",
		inArgs, 1);
	result = (double[]) outputArgs[0];
	System.out.println("Sum of 2-D array is:" + result[0]);
	matlabClient.shutDownServer();
} catch (JamalException e) {
	e.printStackTrace();
}

javaCellArgs2Matlab.m

%---------------------------------------------------
function [matlabArray] = javaCellArgs2Matlab(inCells)
% [matlabArray]=javaCellArgs2Matlab(arg1)
% Take array of Matlab cells that represent 2D java array passed from a java program
% and transforms it into a Matlab array
% 2010-09-27 Harry Rostovtsev - initial version
% 2010-10-10 Maksim Khadkevich - minor changes

yDim = size(inCells, 2);
xDim = size(inCells{1}, 2);

tmpCellArr = [inCells{:}];
tmpReshapedArr = reshape(tmpCellArr, xDim, yDim);
matlabArray = transpose(tmpReshapedArr);

end
%---------------------------------------------------

test2dArray.m

%---------------------------------------------------
function [sumOut] = test2dArray(inMatrix)

in = javaCellArgs2Matlab(inMatrix);
sumOut = sum(in(:));
display(sumOut);

end
%---------------------------------------------------

Advertisements

0 Responses to “FAQ”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: