Help using getmcruserdata and setmcruserdata with JAVA
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello
I am trying to used the MCR user memory to access and modify some data both on the Matlab and JAVA sides. I have added both getmcruserdata.m and setmcruserdata.m functions to my class, so that I can access them in JAVA as well.
I am having problems with both using the right types, which don't seem to match the method signatures, as well as converting those to Java types I can use. The signature for getmcruserdata says it takes an object (or object[] if I import it back into matlab and look at methodsview) and returns an object[]. So I code something like this:
Object[] result = null;
result = myClass.getmcruserdata(key_string);
System.out.println(result[0]);
The problem is that it complains that it exceeds the index bounds with index 0. I redefine the result as a single Object type, and the error disappears. But why the mismatch between the signature and the actual usage?
So now it runs, but I can't figure out how to read this data. I've tried converting to String, I've tried casting to MWArray and MWNumericArray, but it always complains that it can't cast an Object into any of those types.
So I was hoping someone would be so kind to guide me on how to call the getmcruserdata method correctly on Java and how to use the data it returns.
For my first simple example, I am passing a single integer. However, in theory I would like to pass more complex data types such as arrays and structures.
I'd be thankful for any tips!
Kind regards Maria
0 comentarios
Respuesta aceptada
Artik Crazy
el 13 de Oct. de 2011
Hi, Try to create two functions in Matlab that contain getmcruserdata and setmcruserdata:
function SetMCRUserData (Value, Key)
setmcruserdata(Key, Value)
end %function
and:
function Value=GetMCRUserData (Key)
Value=getmcruserdata(Key);
end %function
Then, when building the .jar file add these two functions to your class as two methods. (Not in the "Shared Resources" section but in the upper one.)
In Java use them in this way:
String Key = "MyValue";
MyClass.SetMCRUserData(Value, Key);
Object[] Value =null;
Value=MyClass.GetMCRUserData(1, Key);
System.out.println(((MWNumericArray) Value[0]).getDouble());
This solution worked for me, hope it will help you too.
Más respuestas (1)
Artik Crazy
el 13 de Oct. de 2011
Hi, try this:
Object[] result = null;
result = myClass.getmcruserdata(key_string);
FirstOut=((MWNumericArray) result[0]).getDouble();
SecondOut=((MWNumericArray) result[1]).getDouble();
Ver también
Categorías
Más información sobre Java Package Integration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!