A matrix has m rows and n columns (n being a number not exceeding 10), and the nth column contains either 1 or 0 (binary). I want to use this binary as a decision to take out the associated row (if 1, or otherwise if 0). I understand that this can be done through iteration with the use of the IF conditional.
However, this may become impractical with matrices whose number of rows m gets into the hundreds (up to 1000). What other procedures are available?
You can use
logicaldatatypes for indexing. For example,Now you have set all the elements in column 2 to 1 if the corresponding element in column
nis true.Note that the
v = (M(:,n) == 1)converts thenth column to a logical vector. You can accomplish the same withv = logical(M(:,n));I would recommend this blog entry for a detailed look at logical indexing.
Update:
If you want to erase rows, then use: