convert elements of cell array/struct array to Java primitive data types

조회 수: 1 (최근 30일)
luc
luc 2013년 9월 25일
답변: Mihir Daptardar 2014년 1월 17일
Hi,
I am trying to convert the returned objects when a matlab function is called from Java. If it is numeric array ob.asInstanceOf[MWNumericArray].toArray().asInstanceOf[Array[Array[Double]]] works fine. When it is a cell array or struct array, I can access each element using get() or getField(). They return an object. I want to convert these objects to appropriate Java primitive data types - int, char, numeric array etc. Any ideas about how to find the type of the object(which is a single element of cell array) and how to convert it. The whole idea is to represent cell array as array of elements(an element can be int, char, array etc) and struct array as array of arrays. Please post your suggestions/thoughts. Thank you!

답변 (1개)

Mihir Daptardar
Mihir Daptardar 2014년 1월 17일
If you want to find the type of the object in Java, you can use the following code snippet:
ArrayList<Object> list = new ArrayList<Object>(); // This would contain the list
for (Object object : list) {
System.out.println(object.getClass().getName());
}

카테고리

Help CenterFile Exchange에서 Java Package Integration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by