Main Content

Code Multiple Outputs for Java Client

MATLAB® allows users to write functions that return multiple outputs.

For example, consider this MATLAB function signature:

function [out_double_array, out_char_array] =  
                 multipleOutputs (in1_double_array, in2_char_array) 

In the MATLAB signature, multipleOutputs has two outputs (out_double_array and out_char_array) and two inputs (in1_double_array and a in2_char_array, respectively)—a double array and a char array.

In order to call this function from Java®, the interface in the client program must specify the number of outputs of the function as part of the function signature.

The number of expected output parameters in defined as type integer (int) and is the first input parameter in the function.

In this case, the matching signature in Java is:

public Object[] multipleOutputs(int num_args, double[] 
                        in1Double, String in2Char);
where num_args specifies number of output arguments returned by the function. All output parameters are returned inside an array of type Object.

Note

When coding multiple outputs, if you pass an integer as the first input argument through a MATLAB function, you must wrap the integer in a java.lang.Integer object.

Note the following coding best practices illustrated by this example:

  • Both the MATLAB function signature and the Java method signature using the name multipleOutputs. Both signatures define two inputs and two outputs.

  • MATLAB Java interface supports direct conversion from Java double array to MATLAB double array and from Java string to MATLAB char array. For more information, see Conversion of Java Types to MATLAB Types.

For more information, see Java Client Coding Best Practices.