Problem with assigning subset of multidimensional array

1 回表示 (過去 30 日間)
Alexander
Alexander 2012 年 5 月 30 日
If there is a multidimensional array, say A= rand(3,4,2,2), it is easy to assign, say, the first page with B = A(:,:,1,:), using the colon operator. My problems: (1.) I dont know beforehand the number of dimensions ndim(A) of A and (2.) also not the dimension, in which the assignment will be. So in another case it might be the first row of a 3D-array which has to be assigned A(1,:,:).
Facing the 2. problem, I would use 'permute' or 'shiftdim' to place the dimension, where the assignment should be, to, say, the first dimension. For the example above: A = rand(3,4,2,2); A = shiftdim(A,2); % formerly 3.Dim is now on 1.position
But the 1. problem of unknown number of dimensions stay unsolved. Is there anybody who has an idea? Every help is appreciated.
Alex

回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by