Transform matrix into vector X Y Z
이전 댓글 표시
Hi!
I have a matrix 1024 * 1024 and I need to do a regression with this matrix, but first I need to convert it to a X Y Z vector for example.
2 2 3
1 5 7
9 8 7
Where X = n, Y = m, and Z = value, in order to get the vectors in this form
(1 , 1, 2)
(1 , 2 , 2)
(1, 3, 3)
(2, 1, 1)
(2, 2, 5) , etc
Thank you for your help
채택된 답변
추가 답변 (1개)
Walter Roberson
2021년 3월 18일
편집: Walter Roberson
2021년 3월 18일
A = [
2 2 3
1 5 7
9 8 7]
[X, Y, Z] = find(A);
XYZ = sortrows([X, Y, Z])
Note: this particular implementation does not output 0. If you need 0 then a different implementation would be used.
카테고리
도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!