How to find coordinates of non-zero elements of matrix (not their Linear Indices)?
12 次查看(过去 30 天)
显示 更早的评论
I need to find the coordinates of the non zero elements of a matrix, M1:
M1 =
0.0000e+000 0.0000e+000 0.0000e+000 0.0000e+000
0.0000e+000 0.0000e+000 0.0000e+000 0.0000e+000
0.0000e+000 0.0000e+000 66.0540e+003 64.2759e+003
0.0000e+000 86.9708e+003 81.3036e+003 81.0349e+003
127.9599e+003 120.6672e+003 119.6269e+003 121.4074e+003
I tried using the ind2sub function, but I'm not sure I understood how it works, since it returns something that doesn't make sense to me:
ind = M1;
sz = [5 4];
[row,col] = ind2sub(sz,ind)
row =
0.0000e+000 0.0000e+000 0.0000e+000 0.0000e+000
0.0000e+000 0.0000e+000 0.0000e+000 0.0000e+000
0.0000e+000 0.0000e+000 4.0126e+000 5.8732e+000
0.0000e+000 5.8386e+000 3.6091e+000 4.8630e+000
4.9465e+000 2.1525e+000 1.8986e+000 2.4276e+000
col =
1.0000e+000 1.0000e+000 1.0000e+000 1.0000e+000
1.0000e+000 1.0000e+000 1.0000e+000 1.0000e+000
1.0000e+000 1.0000e+000 13.2110e+003 12.8550e+003
1.0000e+000 17.3940e+003 16.2610e+003 16.2070e+003
25.5920e+003 24.1340e+003 23.9260e+003 24.2820e+003
My objective is to organize this M1 data in a table, with the non-zero elements and their corresponding coordinate. For example:
| Number | Row | Column |
66.0540e+003 3 3
64.2759e+003 3 4
.....
..... and so on
Can someone help me do that? I actually need their row/column coordinates and not their Linear Indices.
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!