MATLAB Answers

Martin
0

Get the row values with some rules

Asked by Martin
on 12 Apr 2018

Hello, imagine I have a table where column 1 is string and column 2 is a ID, and column 3 is the value I want to recieve:

 'hund-hu'  61   546
 'hund-ij'  99   489
 'kat-ij'   69   1651
 'hund-ji'  99   985
 'hund-ok'  99   999

I want to receive bottom values 985 and 999. The position ID have to be equal, and the string have to contain 'hund' (if 'hund' is last in column1). But if it change to contain 'kat' from bottom (as row 3), I don't want to receive values anymore, - even above 'kat' if the ID is the same.. Another example:

 'kat-hu'   69   546
 'hund-ij'  67   489
 'kat-ij'   69   1651
 'kat-ji'   69   985
 'kat-ok'   69   999

Here is need to recieve 1651, 985 and 999. Due to 'kat' go from bottom 3 times in column1 and with same ID...

In the first example above,I have tried

list_the_values=T.column3(T.column2==99 & contains(T.column1,'hund'))

The problem here is I receive: 489 985 999 But I should only receive the last 2, due to 'kat' is present between the 'hund'.

Any suggestion? Thanks

  0 Comments

Sign in to comment.

0 Answers