Here is the sample Java code that accepts variable number of arguments:
public class TestVarArgs { // calculate average of numbers of type 'double' public static double average( double... numbers ) { double total = 0.0; // initialize total for ( double d : numbers ) total += d; return total / numbers.length; } // calculate average of numbers of type 'Double' public static Double averageD( Double... numbers ) { Double total = 0.0; for ( Double d : numbers ) total += d; return total / numbers.length; } }
When I try to invoke any of the above methods in MATLAB as follows:
a = TestVarArgsa.average(7,6)a.averageD(java.lang.Double(23), java.lang.Double(34))
I get the following errors respectively:
??? No method 'average' with matching signature found for class 'VarargsTest'. ??? No method 'averageD' with matching signature found for class 'VarargsTest'.
Best Answer