Manipulating dimensions without using loops

I would like to know if there is a way to manipulate the following high dimensional array with permute or bsxfun or other functions without using so many loops, here iTe1, iTe2,... are known indexing matrices. Thanks in advance!
for i1 = 1:nE1
for i2 = 1:nE2
for i3 = 1:nE3
for i4 = 1:nE4
outputM(:,:,:,:,i1,i2,i3,i4) = inputM(iTe1(:,i1),iTe2(:,i2),iTe3(:,i3),iTe4(:,i4));
end
end
end
end

2 件のコメント

James Tursa
James Tursa 2020 年 6 月 8 日
編集済み: James Tursa 2020 年 6 月 8 日
What is inputM? A variable or a function? What are the dimensions of all of your variables? How are the values in the iTe1,...,iTe4 variables created? Any pattern to them?
Boyi Ye
Boyi Ye 2020 年 6 月 8 日
編集済み: Boyi Ye 2020 年 6 月 8 日
Hi, inputM and outputM are both high dimensional arrays. Basically I want to reshape inputM to outputM. Let's say the dimension of inputM is and I want to reshape it into outputM with dimension . iTe1,...,iTe4 are indexes as. So I want to do like , , etc.
which each of the above can be considered as a block of dimension .
Thank!

回答 (1 件)

James Tursa
James Tursa 2020 年 6 月 9 日

0 投票

It looks like the indexing is consecutive, it is just that you have a mixture of reshaping (which doesn't change memory order of data) and permuting (which does channge memory order of the data) the dimensions. E.g., for your specific example:
inputM = 22 x 22 x 22 x 22 array
r = reshape(inputM,[2,11,2,11,2,11,2,11]);
outputM = permute(r,[1 3 5 7 2 4 6 8]);
Perhaps you can use a variation of this two-step scheme for your actual problem.

1 件のコメント

Boyi Ye
Boyi Ye 2020 年 6 月 10 日
Yes, that's exactly I want. Thank you so much!!

この質問は閉じられています。

製品

質問済み:

2020 年 6 月 8 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by