- 1st row, 2nd column, value 34?
- 12th row, 3rd column, value 4?
- 1st row, 23rd column, value 4?
How to write matrix elements with its position?
9 ビュー (過去 30 日間)
古いコメントを表示
I have a matrix A=[1 2 3; 4 5 6; 7 8 9] I want to write each entry with its row and column position e.g 111 indicates the element 1 at position first row First column , also 328 element 8 at position 3rd row and second column. so with the help of above matrix
A I want the following
111
122
133
214
225
236
317
328
339
Thanking for the anticipation.
1 件のコメント
Guillaume
2018 年 1 月 25 日
While it's very easy to do what you want, what is its purpose? Bearing in mind that if you don't limit A to integers [0-9] and its size to a max of 9 rows and 9 columns, then the operation is irreversible.
What would the value 1234 mean?
採用された回答
Birdman
2018 年 1 月 25 日
編集済み: Birdman
2018 年 1 月 25 日
[r,c]=find(A);
val=sortrows([r c A(:)],1)
2 件のコメント
Guillaume
2018 年 1 月 25 日
That will fail if any value in A is 0.
[r, c] = find(true(size(A));
val = sortrows([r c A(:)],1)
would be safer.
Or:
[c, r] = ndgrid(1:size(A, 2), 1:size(A, 1));
val = [r(:), c(:), a(:)];
その他の回答 (2 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!