How to pass a 3d array double[][][] from java to a Matlab function

1 回表示 (過去 30 日間)
Felipe Reis
Felipe Reis 2018 年 8 月 17 日
コメント済み: James Tursa 2018 年 8 月 23 日
I have a matlab function inside a jar package which is supposed to receive from my java class a double[][][]. Due the difference in the way java and matlab understand array structures when the array arrives to the matlab side it is messed.
Is there a way to convert java 3d array so then each dimension can be read like: (:,:,1) (:,:,2) and (:,:,3) in the matlab function?

採用された回答

James Tursa
James Tursa 2018 年 8 月 17 日
As long as it arrives as a 3D variable but the dimensions seem backwards, perhaps you only need to permute it. E.g.,
x = 3D array from your java
x = permute(x,[3 2 1]); % permute to MATLAB memory ordering
  2 件のコメント
Felipe Reis
Felipe Reis 2018 年 8 月 21 日
@James thanks for your answer. It was the right start to achieve what I wanted. In my case I had to work it out like this: DS is my java double[][][] and from matlab i would like to access each chunk of data like
DS(:,:,indexchunkofdata)
and have a NxM matrix as result so i did:
PDS = permute(DS,[3 2 1])
ChunkOfData = PDS(:,:,indexChunkOfData)
ChunkOfData = ChunkOfData'
So it's kind of the last dimension after the permutation still needed some transpose to invert what was column into lines and vice-versa. Also a side comment is that after the permute new zeros columns where added to the last dimension!? Still don't know the reason. Any insight?
Thanks again
James Tursa
James Tursa 2018 年 8 月 23 日
Try permute(DS,[2 3 1]) to get rid of that extra transpose at the end.
The permute function does not add any elements to the input array. So if you are getting extra 0's they are there before the permute operation.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJava Package Integration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by