0

i am using matlabcontrol API in java to connect matlab and java. I am calling matlab function using returningFeval and passing function name and Object array.

Java Code

 Object[] path = new Object[2];
 path[0]=imgp1;                                       //imgp1,imgp2 path of image file
 path[1]=imgp2;
 Object[] out = proxy.returningFeval("main_single",1,path);

now on matlab side how to retrieve element of this array.i.e in this case i want to extract path[0] and path[1] and store it in some variable.

Matlab Code

function rslt =  main_single(path)

imgp1 = path(0);
imgp2 - path(1);

can anyone please tell me how to do this..?

Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82

2 Answers2

0

finally i found new method to pass arguments from Java to Matlab.insted of passing Object array we can also pass string like

   String in = img1path;
   String in1 = img2path;
   Object[] out = proxy.returningFeval("main_single", 1, in,in1);

where "main_single" is function name which is in matlab. 1 is how many value will be returned from matlab to java and in,in1 is string to be passed.

Matlab code looks like..

function out = main_single(str,str1)
  img1 = str;
  img2 = str1;
  out = img2;
end

returned result will be stored in out[] and can be display like normal java by typecasting.

if someone knows how to retrieve data from an array then please post it.

0

I use the following simple code to convert 1d and 2d arrays from java to Matlab:

function [ res ] = j2mArray( A )
%just for 1d and 2d data.
s=size(A);

res=zeros(s(2),size(A{1},2));
for i=1:s(2)
    for j=1:size(A{1},2)
        res(i,j)=A{i}(j);
    end
end
Hassan
  • 396
  • 5
  • 12