Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: remove multiple rows of matrix based the value and index of row of another matrix
Date: Sat, 20 Mar 2010 18:01:06 +0000 (UTC)
Organization: Saint Louis University
Lines: 40
Message-ID: <ho32h2$3mi$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1269108066 3794 172.30.248.35 (20 Mar 2010 18:01:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 20 Mar 2010 18:01:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 582341
Xref: news.mathworks.com comp.soft-sys.matlab:618559

I have 2 matrices with the same row, matrixA (n  by k) and matrixB (n by 1)

matrixA =

       1              2              3              4       
       5              6              7              8       
       9             10             11             12       
      13             14             15             16       
      17             18             19             20     

matrixB =

       1       
       2       
       2       
       1       
       2    

now I would like to remove row of matrix A, based the value of element in matrix B
For example remove all row of matrixA when value of element in matrixB is equal 2
matrixA = removeRow(matrixB)
matrixA =

       1              2              3              4       
      13             14             15             16       
Only row 1 and row 4 of matrixA remained.

   The code I wrote as a mathlab script:
==========================================
 for i=1:length(matrixB)
             if matrix(1,i) = 2
               index = index+1;
               removeRow(index) = i;
            end
 end

matrixA(removeRow,:)=[]
=========================================
It does not work
???  Index of element to remove exceeds matrix dimensions.