Extracting data from a table

11 ビュー (過去 30 日間)
Teresa Phillips
Teresa Phillips 2016 年 8 月 15 日
コメント済み: Toshikazu Kawagoe 2018 年 6 月 26 日
I have a table with multiple variables most of which are numerical. I have one variable which is categorical, I would like to be able to extract all the data relating to the specific variable.
For example my categories are REST, EXERCISE and RECOVERY. The data is split into 22 different variables (of which the phase is column 20) and I would like to create a table with only the REST data in it.
Currently, the data belongs to 'TestTable' which is a 130x22 table (the number of rows in the table will vary depending on the data set).
Any suggestions would be greatly appreciated, and as simple as possible please!

採用された回答

Guillaume
Guillaume 2016 年 8 月 15 日
This is basic table filtering:
resttable = TestTable(TestTable.Phase == 'REST', :) %select only those rows that are REST and all columns
or
resttable = TestTable(TestTable{:, 20} == 'REST', :)
I'd recommend the first syntax.
  5 件のコメント
Peter Perkins
Peter Perkins 2018 年 3 月 28 日
You need to create a logical vector that is true for rows in those two categories. Ignore tables for a moment. How would you create a logical vector based on two conditions?
Toshikazu Kawagoe
Toshikazu Kawagoe 2018 年 6 月 26 日
I did the same thing for my table data but MATLAB said you cannot use '==' for cell data. What should I do?

サインインしてコメントする。

その他の回答 (1 件)

Pawel Ladosz
Pawel Ladosz 2016 年 8 月 15 日
編集済み: Pawel Ladosz 2016 年 8 月 15 日
Hi Teresa, to get the REST Column from the table the command would look something like this:
A = TestTable{:,{'REST'}}
Or
A = TestTable.REST
Let me know if any of those worked for you.
  2 件のコメント
Guillaume
Guillaume 2016 年 8 月 15 日
If I understood correctly, 'REST' is not a variable of the table, but one of the categories of the 'PHASE' variable.
Pawel Ladosz
Pawel Ladosz 2016 年 8 月 15 日
Yes I think you are correct, I misunderstood the question.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by