Help using getmcruserdata and setmcruserdata with JAVA
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Artik Crazy
2011 年 10 月 13 日
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.
その他の回答 (1 件)
Artik Crazy
2011 年 10 月 13 日
Hi, try this:
Object[] result = null;
result = myClass.getmcruserdata(key_string);
FirstOut=((MWNumericArray) result[0]).getDouble();
SecondOut=((MWNumericArray) result[1]).getDouble();
参考
カテゴリ
Help Center および File Exchange で Java Package Integration についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!