# Pull a conditional subset of a matrix

26 views (last 30 days)
Andres Serrano on 2 Nov 2018
Commented: Walter Roberson on 2 Nov 2018
Hi guys I have a matrix and I want to pull a subset matrix but only with the numbers whose last digit is one. EX a= 00110, 01000, 01011, 01101. thus b= 01011, 01101
##### 4 CommentsShowHide 3 older comments
Andres Serrano on 2 Nov 2018
Hi Walter, you are correct, they are characters. '00110' is the first row. '01000' second row, etc...

Sign in to comment.

### Answers (2)

Walter Roberson on 2 Nov 2018
a(a(:,end)=='1',:)
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 2 Nov 2018
You said the entries were characters, and '1' will not == to 1 .
You also specifically wanted the last digit, but if your array were wider than 5 digits then a(:,5) would not be the last digit.
If your values are numeric instead of character, then a(a(:,end)==1,:)

Sign in to comment.

Fulden Buyukozturk on 2 Nov 2018
If a is a matrix of characters, you can do:
a= ['00110'; '01000'; '01011'; '01101'];
i = strfind(a(:,end)', '1');
b = a(i,:);
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!

Translated by