Get index from elements in a table
22 次查看(过去 30 天)
显示 更早的评论
I'm new to matlab, coming from data analysis in python/Panda. I have some problems working on tables of different data. Let's say I've a table T with some students data stored: one column with names and others with votes (from 0 to 10) for each exam column. I need to find the indexes of students who have votes>=5.
Thank you
2 个评论
Jan
2016-5-16
Please post the code, which reproduces the problem. Then posting a matching answer is much easier. Thanks.
采纳的回答
Matt Cohen
2016-5-18
Hi Fabio,
I understand that you are interested in learning more about how to index into tables using logical expressions.
The MATLAB documentation section titled Access Data in a Table contains an example that shows how to index into a table using a logical expression. I have included some of the example code below, as well as an additional example to the indexing process.
load patients
patients = table(Age,Gender,Height,Weight,Smoker,...
'RowNames',LastName);
rows = patients.Age<30;
vars = {'Gender','Height','Weight'};
T1 = patients(rows,vars);
T2 = patients(patients.Age>30, {'Gender','Height'});
The "patients" data provided by MATLAB is used here. In this example, a new table, 'T1', is created that contains the gender, height, and weight of the patients under the age of 30. The only rows selected are the ones where the value in the variable, 'Age', is less than 30. The dot notation is used to extract data from the table variable, and a logical expression is used to define the subset of rows based on that extracted data. The variable 'rows' is a 100-by-1 logical array containing logical true (1) for rows where the value in the variable, 'Age', is less than 30. Finally, parentheses are used to perform the indexing and to return a table containing the desired subset of the data. A second table, 'T2', is also created and contains the gender and weight data of the subset of patients whose age is over 30.
I hope this information proves to be helpful.
Matt
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!