Accessing a cell in a 2D grid

2 次查看(过去 30 天)
Lama Hamadeh
Lama Hamadeh 2021-7-3
评论: dpb 2021-7-4
Hi all,
I have a 2D grid as shown below where each cell represents a pair of and where and . I would like to construct a new index that combines these two indices to run over all of the cells as a one continous number.
Any help would be appreciated.
Thanks.

回答(1 个)

Cris LaPierre
Cris LaPierre 2021-7-3
Consider using linear indexing. You can find an explanation towards the middle of this page. It is also explained here. If you need to go back and forth between a linear index and row/column indexing, you can use the functions ind2sub and sub2ind.
  6 个评论
Lama Hamadeh
Lama Hamadeh 2021-7-4
That is amazing! Many thanks for that!
dpb
dpb 2021-7-4
Yet again, however, I'd almost wager it isn't the most fruitful approach to the problem...

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by