Interating through a table data set
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Andrew Czeizler
am 5 Mär. 2019
Beantwortet: Andrew Czeizler
am 7 Mär. 2019
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
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 5 Mär. 2019
Bearbeitet: Andrei Bobrov
am 5 Mär. 2019
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)));
0 Kommentare
Weitere Antworten (4)
Siehe auch
Kategorien
Mehr zu Orange finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!