MATLAB Answers

matlab compactibilty

3 views (last 30 days)
Aldin on 14 Mar 2012
Hello people,
Here is my problem:
I have created jar file in MATLAB and i use this jar file in JAVA (NetBeans).
Here is my function in m-file: (name: matrica.m)
function out = matrica(a)
out = a(:,1) %a is matrix
Here is my code in JAVA:
import com.mat.*;
import com.mathworks.toolbox.javabuilder.*;
public class KlasaMat {
* @param args the command line arguments
public static void main(String[] args) throws MWException {
int matrica[][] = new int[3][3];
matrica[0][0] = 1;
matrica[0][1] = 2;
matrica[0][2] = 3;
matrica[1][0] = 4;
matrica[1][1] = 5;
matrica[1][2] = 6;
matrica[2][0] = 7;
matrica[2][1] = 8;
matrica[2][2] = 9;
KlasaMatlab k = null;
k = new KlasaMatlab();
Object[] matrica1 = k.matrica(1, matrica);
But always get an error like this:
{??? Error using ==> matrica
Too many input arguments.
Exception in thread "main" ... Matlab M-code Stack Trace ...
com.mathworks.toolbox.javabuilder.MWException: Error using ==> matrica
Too many input arguments.
at com.mathworks.toolbox.javabuilder.internal.MWMCR.mclFeval(Native Method)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.access$600(
at com.mathworks.toolbox.javabuilder.internal.MWMCR$6.mclFeval(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.mathworks.toolbox.javabuilder.internal.MWMCR$5.invoke(
at $Proxy0.mclFeval(Unknown Source)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.invoke(
at com.mat.KlasaMatlab.matrica(
at KlasaMat.main(
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
What to do?
Aldin on 14 Mar 2012
Well-intentioned proposal: Restrict users to the three questions a day. Can i delete my accepted questions and answers?

Sign in to comment.

Accepted Answer

Friedrich on 14 Mar 2012
the data type you use to pass the matrix down to the ML function is wrong. I think the function signature must be:
public Object[] matrica(int i, Object... os)
So Object and not int[][] is needed => Try
Object[] matrica1 = k.matrica(1, (Object)matrica);
Friedrich on 15 Mar 2012
Good morning,
I would say
int[][] out = (int[][])((MWNumericArray)matrica1[0]).toIntArray();

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!