How to delete rows of a matrix when one column contains a dummy variable
3 views (last 30 days)
Show older comments
I need to resize my data sample. I have a data matrix that looks like:
Data = [lnwages educ exp expsq black married]
Each column of Data is a 13,000 x 1 vector. Hence data is a 13,000 x 6 matrix. Educ, black, married are dummy variables (0's or 1's).
How can I delete all the rows where married = 1? This would change my data so that it only contains unmarried individuals and their corresponding wages, educ, etc.. Married is the sixth column of data.
I would like the output in a new matrix. Call it newdata.
Thanks so much for your help.
0 Comments
Accepted Answer
Azzi Abdelmalek
on 20 Mar 2013
Edited: Azzi Abdelmalek
on 20 Mar 2013
idx=Data(:,6)~=1
newdata=Data(idx,:)
3 Comments
Azzi Abdelmalek
on 20 Mar 2013
Example
x=[1 2 3 4 5]
idx=x>2 % where x is >2 the result is 1, elswhere it's 0
out=x(idx) % is logical indexing, will ignoàre 0 indices.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!