What's an efficient way to pick a specific slice in a high dimensional array
13 ビュー (過去 30 日間)
古いコメントを表示
Hello all, I have an array that can be anywhere from 9 to 16 dimensional. I want to concatinate one of the dimensions into a previous dimension. For example say I have an array where size(array)=[100 100 100 5 5 5 2]. I can "get rid of" the 7th dimension of size 2 by using cat(2, array(:,:,:,:,:,:,1),array(:,:,:,:,:,:,2)). However, Using all of those colins as place holders is very cumbersome and the size of my array can vary but I always want to concatinate the 7th dimension into the second dimension of the array. Does anyone know a slick way to do this?
0 件のコメント
採用された回答
Dave B
2021 年 8 月 10 日
That's a scary looking array!
Not sure how slick it is, but if you're looking to turn those 6 colons into a number 6, you can leverage subsref. It makes more code but maybe easier to parameterize it if that's your goal?
a=rand(8, 7, 6, 5, 4, 3, 2); % using a smaller array than yours...
subsref(a,substruct('()', [repelem({':'},6) 1]));
(Just a proof of concept that it works):
b=cat(2, a(:,:,:,:,:,:,1),a(:,:,:,:,:,:,2));
c=cat(2, ...
subsref(a,substruct('()',[repelem({':'},6) 1])), ...
subsref(a,substruct('()',[repelem({':'},6) 2])));
isequal(b,c)
d = cat(3,repmat(1,4),repmat(2,4),repmat(3,4))
dreshape=reshape(d,4,12)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!