# transposing 3d matrix with permute function

7 ビュー (過去 30 日間)
navan 2023 年 6 月 3 日

I have 3d matrix 1*508*265. I want to use permute function so that I need to get 265*508*1. However the 1 is not shown in matlab (which makes it a 2d wave). So if I want to open this in different application as Igor pro, it assumes the entire wave as 2d as matlab ignores 1 at the end. Can someone kindly help here?

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

### 回答 (2 件)

James Tursa 2023 年 6 月 3 日

MATLAB does not store trailing singleton (1) dimensions beyond the 2nd dimension. Once you permute that 1 into the 3rd dimension, it is not stored. But you can still treat the variable in MATLAB as if that dimension is there. E.g.,
x = reshape(1:6,2,3)
x = 2×3
1 3 5 2 4 6
x(2,:)
ans = 1×3
2 4 6
x(2,:,1) % works
ans = 1×3
2 4 6
x(2,:,1,1,1,1,1,1,1,1) % also works!
ans = 1×3
2 4 6
size(x) % the 1 in the 3rd dimension is not stored and is not reported
ans = 1×2
2 3
size(x,3) % but if you specifically request it, it works
ans = 1
As for 3rd party applications, how does Igor Pro get the dimensions from MATLAB?
##### 0 件のコメント表示 -1 件の古いコメント非表示 -1 件の古いコメント

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

John D'Errico 2023 年 6 月 3 日

You CANNOT tell MATLAB that a matrix is explicitly 265x508x1, and have it recognize that third singleton dimension. Yes, if you use size, and so interogate that third dimension, it will tell you it is of size 1.
But if you then pass it to a third party tool, MATLAB will still pass it as 2d.
However, can you make the array 265x508x2? That is, just use repmat to replicate the first plane into a second identical plane.
A = rand(265,508);
size(A)
ans = 1×2
265 508
A = repmat(A,[1 1 2]);
size(A)
ans = 1×3
265 508 2
Now you can pass this array into that tool. Do as you wish with the replicated data.

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

### カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

### Community Treasure Hunt

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

Start Hunting!