Transform matrix into vector X Y Z

6 ビュー (過去 30 日間)
Fernando Lobo
Fernando Lobo 2021 年 3 月 18 日
コメント済み: Fernando Lobo 2021 年 3 月 18 日
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

採用された回答

KSSV
KSSV 2021 年 3 月 18 日
You may follow something like this:
A = [2 2 3
1 5 7
9 8 7];
[m,n] = size(A) ;
[X,Y] = meshgrid(1:n,1:m) ;
P = [X(:) Y(:) A(:)]
  1 件のコメント
Fernando Lobo
Fernando Lobo 2021 年 3 月 18 日
Thank you very much!

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 3 月 18 日
編集済み: Walter Roberson 2021 年 3 月 18 日
A = [
2 2 3
1 5 7
9 8 7]
A = 3×3
2 2 3 1 5 7 9 8 7
[X, Y, Z] = find(A);
XYZ = sortrows([X, Y, Z])
XYZ = 9×3
1 1 2 1 2 2 1 3 3 2 1 1 2 2 5 2 3 7 3 1 9 3 2 8 3 3 7
Note: this particular implementation does not output 0. If you need 0 then a different implementation would be used.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by