Pull a conditional subset of a matrix

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

madhan ravi
madhan ravi 2018년 11월 2일
편집: madhan ravi 2018년 11월 2일
More explanation?
Andres Serrano
Andres Serrano 2018년 11월 2일
thanks Madhan. I have a= 00110, 01000, 01011, 01101. I want to get b= 01011, 01101. Matrix b is all the vectors from matrix a whose last digit=1 (when the last digit of a vector in matrix a=0 the vector is not included in matrix b).
Walter Roberson
Walter Roberson 2018년 11월 2일
Are the entries for the first row '00110' which is to say characters? Are they [0 0 1 1 0] which is to say distinct decimal numbers? Are they 00110 decimal, which would show up as 110, decimal one hundred and ten?
Andres Serrano
Andres Serrano 2018년 11월 2일
Hi Walter, you are correct, they are characters. '00110' is the first row. '01000' second row, etc...

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2018년 11월 2일

0 개 추천

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

댓글 수: 2

Andres Serrano
Andres Serrano 2018년 11월 2일
thanks Walter i figured out the line based in your answer. a(a(:,5)==1,:)
Walter Roberson
Walter Roberson 2018년 11월 2일
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,:)

댓글을 달려면 로그인하십시오.

Fulden Buyukozturk
Fulden Buyukozturk 2018년 11월 2일

0 개 추천

If a is a matrix of characters, you can do:
a= ['00110'; '01000'; '01011'; '01101'];
i = strfind(a(:,end)', '1');
b = a(i,:);

카테고리

도움말 센터File Exchange에서 Numeric Types에 대해 자세히 알아보기

질문:

2018년 11월 2일

댓글:

2018년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by