get all rows from table by more than one categorical

1 回表示 (過去 30 日間)
markus tripolt
markus tripolt 2024 年 8 月 16 日
コメント済み: nick 2024 年 8 月 16 日
Hi All,
I want to filter my table and get subtables for statistical calcs.
I use the commant:
D=table
D_sub=D(D.LogID== '2',:);
To get all rows with the LogID 2. How can I expand this commant to get for example all data from LogID 2,3,4 and 5 with one commant?
Than you
Markus

採用された回答

nick
nick 2024 年 8 月 16 日
編集済み: nick 2024 年 8 月 16 日
Hi Markus,
You can retreive get all data for various LogID values with a single command using the function 'ismember', as shown below:
% Define the LogID values you want to filter
logIDsToFilter = {'2', '3', '4', '5'};
% Use ismember to filter the table
D_sub = D(ismember(D.LogID, logIDsToFilter), :);
This command filters the table D to include only the rows where LogID matches any of the specified values. You can refer to the following documentation to learn more about 'ismember' function :
Hope this helps!
  2 件のコメント
markus tripolt
markus tripolt 2024 年 8 月 16 日
Thank you Neelanshu!
Thats exactly what I needed :)
nick
nick 2024 年 8 月 16 日
Glad to know that markus. If you feel that the query has been answered, please feel free to accept the mentioned answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by