フィルターのクリア

Interating through a table data set

1 回表示 (過去 30 日間)
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 5 日
回答済み: Andrew Czeizler 2019 年 3 月 7 日
Hi all,
Im trying to learn how to isolate data from control statements in a table.
Observe the below code -
I am getting some strange results.
Any help would be very much appreciated.
Best,
Andrew
age = input("please input the age: ");
sex=input("please input the gender (M/F):", 's');
%create tables%
%age table
agelow=[30;35;40;45;50;55;60;65; 70];
agehigh= [34;39; 44;49;54;59;64;69;74];
pointsfemale =[-9;-4;0;3;6;7;8;8;8];
pointsmale = [-1; 0; 1; 2 ; 3; 4; 5; 6 ; 7];
agetable=table(agelow, agehigh, pointsfemale, pointsmale)
%if age >= agelow & age<=agehigh & sex== 'F'
for row = 1:height(agetable)
if age >=agelow & age <=agehigh & sex =='F'
test=agetable{row,pointsfemale}
else
test=agetable{row, pointsmale}
end
end

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 3 月 5 日
編集済み: Andrei Bobrov 2019 年 3 月 5 日
sex = {'F';'M'};
age = [55;40];
[~,~,ii] = histcounts(age,agetable.agelow);
[lo,jj] = ismember(sex,{'F','M'});
at = agetable{:,3:4};
test = at(sub2ind(size(at),ii,jj(lo)));

その他の回答 (4 件)

Andrew Czeizler
Andrew Czeizler 2019 年 3 月 5 日
Amazing!
But Im not sure whats going on in the code?
Could you possibly help me understand it.
Pretty awesome though!
Thank you :)
Best,
Andrew

Andrew Czeizler
Andrew Czeizler 2019 年 3 月 5 日
pretty brillant!!!
Thank you champion :).
Best,
Andrew

Andrew Czeizler
Andrew Czeizler 2019 年 3 月 7 日
Hi Andrei
I have another table that im struggling with.
sex=input("please input the gender (M/F): ", 's');
sysbp= input("enter styloic blood pressure: ");
diabp= input("enter dystolic blood pressure: ");
systoliclow=[-inf;-inf;-inf;-inf;-inf;-inf;-inf;-inf;-inf;-inf;
120;120;120;120;120;120;120;120;120;120;
130;130;130;130;130;130;130;130;130;130;
140;140;140;140;140;140;140;140;140;140;
160;160;160;160;160;160;160;160;160;160]
systolichigh =[119;119;119;119;119;119;119;119;119;119;
129;129;129;129;129;129;129;129;129;129;
139;139;139;139;139;139;139;139;139;139;
159;159;159;159;159;159;159;159;159;159;
inf;inf;inf;inf;inf;inf;inf;inf;inf;inf]
diastoliclow=[-inf; -inf ; 80; 80 ; 85; 85 ; 90; 90; 100; 100 ;
-inf; -inf ; 80; 80 ; 85; 85 ; 90; 90;100;100;
-inf; -inf ; 80; 80 ; 85; 85 ; 90; 90;100;100 ;
-inf; -inf ; 80; 80 ; 85; 85 ; 90; 90;100;100 ;
-inf; -inf ; 80; 80 ; 85; 85 ; 90; 90;100;100 ]
diastolichigh=[79; 79 ;84; 84; 89; 89; 99; 99; inf; inf;
79; 79 ;84; 84; 89; 89; 99; 99; inf; inf;
79; 79 ;84; 84; 89; 89; 99; 99; inf; inf
79; 79 ;84; 84; 89; 89; 99; 99; inf; inf
79; 79 ;84; 84; 89; 89; 99; 99; inf; inf]
gender={'F' ;'M'; 'F' ;'M'; 'F' ;'M'; 'F' ;'M';'F' ;'M';
'F' ;'M'; 'F' ;'M'; 'F' ;'M'; 'F' ;'M';'F' ;'M' ;
'F' ;'M'; 'F' ;'M'; 'F' ;'M'; 'F' ;'M';'F' ;'M';
'F' ;'M'; 'F' ;'M'; 'F' ;'M'; 'F' ;'M';'F' ;'M';
'F' ;'M'; 'F' ;'M'; 'F' ;'M'; 'F' ;'M';'F' ;'M' }
values= [-3 ;0; 0 ;0; 0; 1; 2 ;2; 3 ;3;
0;0;0;0;0;1;2;2;3;3;
0;1;0;1;0;1;2;2;3;3;
2;2;2;2;2;2;2;2;3;3;
3;3;3;3;3;3;3;3;3;3]
bpt= table(systoliclow, systolichigh, diastoliclow,diastolichigh, gender, values)
if sysbp>=bpt.systoliclow && sysbp<=bpt.systolichigh && diabp<=bpt.diastoliclow &&
diap>=bpt.diastolichigh && ismember(sex,{'F','M'});
test = bpt.values

Andrew Czeizler
Andrew Czeizler 2019 年 3 月 7 日
I was wondering if you could show me some of your magic :).
Many thanks in advance,
Andrew

カテゴリ

Help Center および File ExchangeAnalysis of Variance and Covariance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by