I have a N1 x N2 x N3 dimension Tensor T. Plus I have a 1 x 3 array a = [a1 a2 a3]. How do I access element T(a1,a2,a3). Is there any way to do this for N dimension.

 採用された回答

Walter Roberson
Walter Roberson 2018 年 6 月 7 日
編集済み: Walter Roberson 2018 年 6 月 7 日

1 投票

acell = num2cell(a);
T(acell{:})
There are also ways to calculate the location as a linear index based upon size(T)
Ts = size(T):
La = length(a);
Ts(end+1:La) = 1;
idx = a(1) + sum((a(2:end)-1) .* cumprod(Ts(1:La-1)))
T(idx)
... if I didn't miss something.

1 件のコメント

Rohit Gupta
Rohit Gupta 2018 年 6 月 7 日
Thanks! I wanted to avoid doing something you mentioned below. First solution works.

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

その他の回答 (1 件)

James Tursa
James Tursa 2018 年 6 月 7 日

0 投票

doc sub2ind

1 件のコメント

Rohit Gupta
Rohit Gupta 2018 年 6 月 7 日
Thanks! But it also needs giving a1,a2,a3 and wont work for any general dimension.

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

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by