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
Jan 2016-5-16
Please post the code, which reproduces the problem. Then posting a matching answer is much easier. Thanks.
Fabio Pasquarella
Fabio Pasquarella 2016-5-16
I'm sorry, I don't have any code, it was just an example. I need to know how to extract indexes from a table given a logical statement on some columns. Sorry for my english

请先登录,再进行评论。

采纳的回答

Matt Cohen
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 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by