how to extract elements along specified dimension of array
88 views (last 30 days)
when e.g. selecting all elements in the 2nd dimension and the first element of all remaining dimensions of an array, for a 3-dimensional array one would write: A(1,:,1)
how to program this elegantly when the dimension over which I want the elements (2 in the example) is a variable itself, whose value is unknown until runtime ?
More Answers (2)
per isakson on 15 Mar 2012
where ixi,ixj,and ixk are numerical vectors (/scalar) of integers. ":" would correspond to (1:number_of_element_in_dimension). Or with logical indexing
where isi,isj,isk are logical vectors all with the length "number_of_element_in_dimension". ":" would be true(1,number_of_element_in_dimension).
The elegance will be in the calculation of ixi,ixj,and ixk or isi,isj,isk.