The colon notation used in multidimensional array
8 views (last 30 days)
Show older comments
I have come across the following notation in MATLAB
y(:, :, :, 2) = y(:, :, :, 1);
y(:, 1, :, 4) = y(:, 1, :, 3);
I have no clue what it means?
I know for matrix A(:,1) and A(1,:) means extract first column and first row respectively. But the above is not clear to me.
Thanks.
0 Comments
Accepted Answer
Adam
on 28 Apr 2015
It is just an extension of what you already know, but for multi-dimensional arrays. You can no longer use terms like 'rows' and 'columns' unless you have n ever more creative names for each dimension, but the logic is the same. Take all data from the dimensions that have a : and only the specified data from the dimensions which you give an exact index for.
Personally I rarely if ever use arrays of dimensionality higher than 3 because I like to be able to visualise what indexing means and since I can't visualise beyond a 3d cube I easily get confused. That said, the logic works the same whether it can be visualised intuitively or not!
4 Comments
More Answers (1)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!