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!