How do I index an array/cell array with an array?
1 次查看(过去 30 天)
显示 更早的评论
I am sorry, it's a very newbie question, but I am nearly lost.
So I have a cell array
data2 = num2cell(magic(5))
And I have an array of size 2.
coord = [x, y]
I want to obtain data2{x,y}
without writing data2{coord(1), coord(2)}
Is it possible to do that?
data2{ coord } gives a completely different result.
0 个评论
回答(2 个)
Star Strider
2015-11-29
You have to write ‘data2{coord(1), coord(2)}’. That’s just the way indexing works.
0 个评论
Image Analyst
2015-11-29
If coord is really a 2 element array and not some larger matrix, then you could use sub2ind() but honestly I think that would just make it more cryptic and less maintainable than doing data2{coord(1), coord(2)}.
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!