Indexing arrays with matrices
2 次查看(过去 30 天)
显示 更早的评论
Matt's recent Hump-day challenger has led me ponder a strange form of indexing used in repmat. Consider a 3d array like the following:
A = reshape(1:8,[2 2 2])
A(:,:,1) =
1 3
2 4
A(:,:,2) =
5 7
6 8
Now run repmat and stop at the second last line:
B = A(subs{:});
Putting in the values for subs, this is the same as
B = A([1 1; 2 2],[1; 2],[1 1; 2 2]);
How is MATLAB interpreting indexing like this?
0 个评论
采纳的回答
Matt Fig
2011-3-31
Now that is the kind of wondering that lead me to the project which lead me to the challenger!
I think we can see what is going on by taking it one at a time:
A([1 1; 2 2],:,:)
So this produces the same thing as this:
A([1 2 1 2],:,:) % Read the indexing array as (:).
Now it makes sense: Take - Row one, then Row two, then Row one, then Row two for all higher dimensions (i.e., for each column and page).
Similarly with the other indexing arrays.
REPMAT and BSXFUN are deep funtions in terms of really understanding how they (and consequently, MATLAB indexing in general) work.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!