How to extract rows from a large number of rows that matchs a unique element in the column
    2 ビュー (過去 30 日間)
  
       古いコメントを表示
    
eg
       ID             Test1         Test2        Test 3                                                                               
       1               10.1          100         100
       2               200           0.1         400
       3               50            80          20.123     
       4               1000          2000        3000
       5               0              1          10.987
say i have a column vector a = [ 20.123 10.987]' my desired result would be ans=
       3        50       80          20.123  
       5         0        1          10.987
I have a set of column vector a = (42x1)' and wish to filter through a large number of rows in a matrix to extract rows from specific column which matches with one element of my column vector. can we use logical indexing for this?
6 件のコメント
  Walter Roberson
      
      
 2018 年 10 月 21 日
				Ah. When I was reading the question on my phone, I could not see the additional columns in the matrix.
採用された回答
  madhan ravi
      
      
 2018 年 10 月 21 日
        
      編集済み: madhan ravi
      
      
 2018 年 10 月 21 日
  
      >> matrix =        [  1               10.1          100         100
                      2               200           0.1         400
                      3               50            80          20.123     
                      4               1000          2000        3000
                      5               0              1          10.987 ];
                  a = [ 20.123 10.987]
                  idx = ismember(matrix,a);
                  [idx1,~]= find(idx==1);
                  myreesult = matrix((idx1),:)
a =
     20.1230   10.9870
myresult =
      3.0000   50.0000   80.0000   20.1230
      5.0000         0    1.0000   10.9870
>>
4 件のコメント
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Logical についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


