How can I index for a specific value in a table?
6 views (last 30 days)
Show older comments
Hello,
For a statistical analysis I made a csv file. Imported it with use of the import tool. The colums I have are subject_nr, cue, set_size, order, deg_0 and correct_0. The statistical analysis needs to be preformed for each participant separate.
So I'm looking for a way to index from my table all the information from only 1 participant. I can index the whole row with subject_nr but thats not what I need.
0 Comments
Answers (1)
Steven Lord
on 19 Mar 2018
Logical indexing.
load patients
T = table(LastName, Gender, Age)
allMalePatients = T(ismember(T.Gender, 'Male'), :)
If you made Gender a categorical array then it becomes even easier.
GenderCat = categorical(Gender);
T2 = table(LastName, GenderCat, Age);
allMalePatients2 = T2(T2.GenderCat == 'Male', :)
Check that the two tables list the same patients (for purposes of this example, the patients each have a unique combination of last name and age.)
isequal(allMalePatients(:, {'LastName', 'Age'}), allMalePatients2(:, {'LastName', 'Age'}))
2 Comments
Peter Perkins
on 23 Mar 2018
What is it that you expect pp(i) to be? If you want to split the table into subtables, create pp as a 1x16 cell array and assign as pp{i} = ... .
But it's likely that you don't need to split your data like that. There are a number of ways to work on grouped data across all groups, in one table. See, for example, varfun and findgroups/splitapply.
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!