テーブル配列の任意の​値が含まれる行のみ取​り出すにはどうすれば​よいですか?

조회 수: 29 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2022년 7월 27일
답변: MathWorks Support Team 2022년 7월 27일
テーブル配列において、特定の列の、任意の値が含まれる​行のみを取り出す方法を教えてください。
例えば、以下のようなテーブルにおいて、Smoker が true の行のみを抽出する方法があれば教えてください。
LastName = ["Sanchez";"Johnson";"Zhang";"Diaz";"Brown"];
Age = [38;43;38;40;49];
Smoker = [true;false;true;false;true];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
Gender = {'f';'f';'m';'m';'f'};
patients = table(LastName,Age,Smoker,Height,Weight,BloodPressure,Gender)

채택된 답변

MathWorks Support Team
MathWorks Support Team 2022년 7월 27일
テーブルデータの特定の値へアクセスする場合、例えば以下のように == の論理値を用いることが可能です。
% Smoker = true の行のみアクセス
P_Smoker = patients(patients.Smoker == true,:)
また、任意の文字列を検出したい場合には matches 関数や contains 関数を使用することができます。
patients(matches(patients.Gender, 'm'),:) % 完全一致
% もしくは
patients(contains(patients.Gender, 'm'),:) % 部分一致
テーブルデータでのデータ抽出方法の詳細については、以下の URL よりヘルプドキュメントをご覧ください。
・table 内のデータへのアクセス

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 table에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!