Seperate the data of a table

1 view (last 30 days)
lakehead
lakehead on 23 Oct 2018
Edited: jonas on 23 Oct 2018
Hello,
I have a table and would like to get out the specific lines based on chosen strings of the first and second column. Means when you look at the attached picture, I would like to have e.g. all the lines with 'Fossil Gas' and 'NO_1' and maybe build them up in a new table or better just take out the values of the last column.
Thank you for the answer! :)

Accepted Answer

jonas
jonas on 23 Oct 2018
Edited: jonas on 23 Oct 2018
Just use logical indexing
T{strcmp(T{:,1},'Fossil Gas'),end}
The line
strcmp(T{:,1},'Fossil Gas')
returns a logical vector where rows matching the target string are true. This vector is then used to extract values from the last (end) column.
Depending on what you are trying to do, it may be wise to use the first column as a grouping variable, and evaluate the other columns group-wise.
  4 Comments
lakehead
lakehead on 23 Oct 2018
Thank you perfect and for the tip with the grouping, too!!! I think it might be better.
jonas
jonas on 23 Oct 2018
Edited: jonas on 23 Oct 2018
My pleasure! Your data set indeed seems ideal for grouping. To get you started, you can look into the following functions
  • findgroups & splitapply
  • varfun
  • grpstats
They are three different functions for evaluating grouped data. If I had to pick one... I would probably go for varfun.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!