フィルターのクリア

unique rows of matrix

198 ビュー (過去 30 日間)
xplore29
xplore29 2013 年 3 月 25 日
I have to create new matrix A from a given matrix B in the following manner
B=[1 4 2;1 5 2;1 5 2;3 3 4;3 1 4;2 1 3;2 6 3]
A=[1 2;3 4;2 3]
i-e in forming A we ignore the values which 2nd column takes in and considers only column 1 and 3 create A.
unique(A,'rows') will not do the job . Do I have to create an intermediate matrix from column 1 and 3 and the apply this unique function to get the desired matrix or is there any other option available which avoids formulation of intermediate matrix

採用された回答

Matt Kindig
Matt Kindig 2013 年 3 月 25 日
You can easily perform the task using:
A = unique( B(:,[1 3]), 'rows');
But of course, this forms the intermediate matrix to run the unique() function. Is there a particular reason you need to avoid this intermediate matrix running (memory issues, perhaps)?
  1 件のコメント
xplore29
xplore29 2013 年 3 月 25 日
I need to create such matrices multiple times. So I was thinking of avoiding this additional step

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

その他の回答 (1 件)

Matt J
Matt J 2013 年 3 月 25 日
編集済み: Matt J 2013 年 3 月 25 日
You have to create an intermediate matrix, but you don't have to assign it to a variable.
A = unique(B(:,[1 3]),'rows')
What issue do you have with the above? Your B matrix is too small for this to matter and super-large matrices will be painful for UNIQUE anyway.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by