matlab compactibilty

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
end
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);
System.out.println(matrica1[0]);
}
}
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(MWMCR.java:25)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$6.mclFeval(MWMCR.java:918)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$5.invoke(MWMCR.java:816)
at $Proxy0.mclFeval(Unknown Source)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.invoke(MWMCR.java:492)
at com.mat.KlasaMatlab.matrica(KlasaMatlab.java:195)
at KlasaMat.main(KlasaMat.java:37)
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
What to do?

8 Comments

Aldin
Aldin on 14 Mar 2012
please help
Aldin
Aldin on 14 Mar 2012
Is it possible that nobody knows the answer??? Please
You're assuming knowledge of JAVA, try to ask on StackOverflow.
Aldin
Aldin on 14 Mar 2012
I think it's quetsion about matlab not about java
Yes, it IS possible that no-one knows the answer. I have not yet encountered anyone who is an expert on _everything_ to do with computer programming.
What is even more likely is that no-one who knows the answer happened to be awake and active on MATLAB Answers at the time you posted, which was 7 AM in the time-zone I live in. Most of North America switched to Daylight Savings Time on Sunday, so our bodies are still telling us that that was 6 AM.
Please keep your messages respectful.
Aldin
Aldin on 14 Mar 2012
Ok, i understand. I thought that there are many developers who are always here.
Everyone who answers questions here is a volunteer, answering in their spare time (except when Helen or Ned post official statements.) Relatively few of the volunteers here happen to work for MathWorks, and of those who do, the ones who are developers happen to be mostly on the Simulink side it appears.
The Active volunteers are mostly in Western Europe, or Eastern North America, with a small number of outliers (e.g., Central North America). The largest portion of answers by far comes from a fairly small number of individual volunteers. There are no "shifts" or the like, nor has anything like that ever been attempted, and the population of active volunteers is too small for anything like that to be practical. About 7 active volunteers on average are handling 80% of the questions from the 56500 forum members.
Aldin
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
Friedrich on 14 Mar 2012
Hi,
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);

13 Comments

Aldin
Aldin on 14 Mar 2012
guten Tag, Friedrich :)
Yes it works, but here is my result:
run:
out =
1
4
7
1
4
7
BUILD SUCCESSFUL (total time: 5 seconds)
Aldin
Aldin on 14 Mar 2012
The numbers (1,4,7) are correct. But there is a duplicate one
Friedrich
Friedrich on 14 Mar 2012
One from Java and one from your MATLAB code because you didnt put a ; at the end of the line out = a(:,1) %a is matrix. So try
out = a(:,1); %a is matrix
Aldin
Aldin on 14 Mar 2012
Yes, thank you so much. You helped me a lot. God bless you.
I only have one more question (maybe it's a more JAVA question)
Know, you can see my code. How to store the result(Object matrica1) in an integer array
Friedrich
Friedrich on 14 Mar 2012
No tested but when I would have to guess:
int[] out = ((MWNumericArray)matrica1[0]).getIntData();
Aldin
Aldin on 14 Mar 2012
You are awesome, thank you man. Are you the second father of JAVA (if we except Dr. James Gosling) :)?
Friedrich
Friedrich on 14 Mar 2012
hehe thanks :)
Since its answered, can you except my answers please?
Aldin
Aldin on 14 Mar 2012
Sure my friend :)
Aldin
Aldin on 14 Mar 2012
Are you from Germany?
Friedrich
Friedrich on 14 Mar 2012
yes i am. Thanks for excepting.
Aldin
Aldin on 14 Mar 2012
Thanks once again. God bless you and FC Bayern Munchen (7:0) :)
Aldin
Aldin on 14 Mar 2012
Friedrich: Your code:
int[] out = ((MWNumericArray)matrica1[0]).getIntData(); is good
But what is when it comes from matrix? How to store the result(Object matrica1) in an matrix (dimension 3x3)?
Friedrich
Friedrich on 15 Mar 2012
Good morning,
I would say
int[][] out = (int[][])((MWNumericArray)matrica1[0]).toIntArray();

Sign in to comment.

More Answers (0)

Asked:

on 14 Mar 2012

Community Treasure Hunt

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

Start Hunting!