フィルターのクリア

what wrong I am doing in the code?

3 ビュー (過去 30 日間)
Manav Divekar
Manav Divekar 2021 年 11 月 18 日
編集済み: Manav Divekar 2021 年 11 月 18 日
i have to filter out female above age 30 and less than 40 fron the give data base
'name', {'mary','john','anna','paul','elaina'},
'gender',{'f', 'm', 'f', 'm', 'f'},
'age' ,{25, 35, 30, 22, 38}
Using structure method
function [patient] = filterpatients_struct(data)
t=array2table(data(2:end,:),'gender',data(1,:));
t.name=string(t.name);
t.gender=categorical(t.gender);
t.age=cell2mat(t.age);
t.name(t.gender=="f");
patient = t.name(t.gender=="f");

回答 (1 件)

KSSV
KSSV 2021 年 11 月 18 日
% Make required structure
S = struct ;
S.name = {'mary','john','anna','paul','elaina'} ;
S.gender = {'f', 'm', 'f', 'm', 'f'} ;
S.age = [25, 35, 30, 22, 38] ;
idx = strcmp(S.gender,'f') ; % Indices of females
iwant = S.age(S.age(idx) >=30 & S.age(idx) <= 40 ) % age criteria
  7 件のコメント
KSSV
KSSV 2021 年 11 月 18 日
Write the given code into a a function.
Manav Divekar
Manav Divekar 2021 年 11 月 18 日
編集済み: Manav Divekar 2021 年 11 月 18 日

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

カテゴリ

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

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by