Pull a conditional subset of a matrix

10 ビュー (過去 30 日間)
Andres Serrano
Andres Serrano 2018 年 11 月 2 日
コメント済み: Walter Roberson 2018 年 11 月 2 日
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 件のコメント
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 日
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 日
If a is a matrix of characters, you can do:
a= ['00110'; '01000'; '01011'; '01101'];
i = strfind(a(:,end)', '1');
b = a(i,:);

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by