How to delete rows of a matrix when one column contains a dummy variable

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.

 Accepted Answer

idx=Data(:,6)~=1
newdata=Data(idx,:)

3 Comments

Great Answer! Would you mind explaining what's going on here? I'm an Econ grad student and this command will most likely change my life.
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.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!