Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
メンバーが 1 から 27 の 3x3x3 の Matlab 配列があるとします。
a=reshape(1:27, [3 3 3])
次のような構文でこれのサブセットを作成したいと思います
b=a(range1,range2,range3)
range1=range2=range3=1:2 の場合、メンバーb(1,1,1)とb(2,2,2). すなわち
b(1,1,1)
b(2,2,2)
b= [1 14]
インデックス作成だけで、関数 (diag など) を使用せずにこれを行うことは可能ですか? ありがとう...
sub2ind次のような関数で実行できます。
sub2ind
b=a(sub2ind(size(a),range1,range2,range3)) ans: b=[1 14]
sub2ind索引付けは、を使用して行うことができます。
a(sub2ind(size(a),[1:2],[1:2],[1:2]))
すべての関数を避けたい場合は、線形インデックスを自分で計算できます...