Function to take grid reference
2 次查看(过去 30 天)
显示 更早的评论
fairly new to this, would any body be able to tell me how i can create a function that can take a grid reference eg A10, C4, F6, etc and convert it into a row and column index? oh btw the grid has to be ten by ten!
0 个评论
采纳的回答
更多回答(1 个)
Walter Roberson
2015-12-9
Under the condition that it is 10 by 10 exactly,
r1 = GR(1) - 'A' + 1;
if length(GR) == 2
r2 = GR(2) - '0';
else
r2 = 10;
end
You do not specify whether the letters indicate rows or columns so make the appropriate choice [r1,r2] or [r2,r1]
If the grid can be larger than 10 x 10 then the "else" would have to be adjusted. If the grid can be larger than 26 then the r1 logic would need to be adjusted.
2 个评论
Walter Roberson
2015-12-9
Note: Stephen's code is more compact; my code is more efficient for the particular requirements that were given.
另请参阅
类别
在 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!