Asked by Andres Serrano
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

Answer by Walter Roberson
on 2 Nov 2018

a(a(:,end)=='1',:)

Andres Serrano
on 2 Nov 2018

thanks Walter i figured out the line based in your answer. a(a(:,5)==1,:)

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.

Answer by 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,:);

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## madhan ravi (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/427510-pull-a-conditional-subset-of-a-matrix#comment_631511

## Andres Serrano (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/427510-pull-a-conditional-subset-of-a-matrix#comment_631513

## Walter Roberson (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/427510-pull-a-conditional-subset-of-a-matrix#comment_631520

## Andres Serrano (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/427510-pull-a-conditional-subset-of-a-matrix#comment_631522

Sign in to comment.