How to take only few rows in a large matrix

2 ビュー (過去 30 日間)
afrya
afrya 2013 年 11 月 11 日
コメント済み: Image Analyst 2013 年 11 月 11 日
Dear All,
I'm working with a large amount of data in a matrix.My problem is the following one.
I have a large matrix which looks like:
  • Initial matrix
X Y Z
0.2 0 6
0.4 0 7
0.6 0 8 values of Y are repeated a lot of time
.. .. ..
.. .. ..
0.1 2 9
0.4 2 10
0.8 2 11
.. .. ..
11 4 6
12 4 8
4 4 9
  • Final marix
X Y Z
0.2 0 6
0.1 2 9
11 4 6
My goal is to take few rows of the matrix because Y values are repeated.
  1 件のコメント
Image Analyst
Image Analyst 2013 年 11 月 11 日
Which row do you want to take? The first row when that value of Y appears? Are y always integers or can they be fractional?

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

回答 (1 件)

A Jenkins
A Jenkins 2013 年 11 月 11 日
編集済み: A Jenkins 2013 年 11 月 11 日
You can use the function unique()
[C,IA,IC]=unique(A(:,2))
A(IA,:)
Or perhaps if you already know the indicies of the rows you want, you can select them row-wise:
idxIwant=[1 3 9]
C=A(idxIwant,:);
  1 件のコメント
afrya
afrya 2013 年 11 月 11 日
Thanks for your answer but I don't know the indices of the rows, the matrix that I'm working with has 700 000 rows. I'll do it with the function unique

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by