필터 지우기
필터 지우기

finding the value in a table

조회 수: 22 (최근 30일)
Lorraine Williams
Lorraine Williams 2015년 10월 16일
댓글: Lorraine Williams 2015년 10월 16일
I have a table and I wish to store the value of the 'rating pts' column in a variable when the column 'yds per att'= 7.21 (there are two values in the table (see example).
What command do I use to get the value in the last column when another column is a value??
Thanks

채택된 답변

Peter Perkins
Peter Perkins 2015년 10월 16일
You said "table". Your screenshot looks a whole lot like a spreadsheet. It would help to be more clear.
Assuming you mean that you used readtable to read that spreadsheet into a table, then you probably ended up with variables in the table named YrdsPerAtt and RatingPts, so do this:
T.RatingPts(T.YrdsPerAtt == 7.21)
Again, there is documentation for this, this page is a good starting point.
  댓글 수: 1
Lorraine Williams
Lorraine Williams 2015년 10월 16일
Hi Peter
Thank you - this is exactly what I needed. You were right - I did read it into a table as you stated.
Sorry for not being precise enough - this is all new to me and so, reading the help (which I'd already found) didn't help me much either on this particular issue.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Naga A
Naga A 2015년 10월 16일
Suppose if you store that table in the matrix named " table" then you can use this one:
table(find(table(:,column number of "yds per att")=="your required 'yds per att"),column_number of "Rating Pts")

Walter Roberson
Walter Roberson 2015년 10월 16일
There are no entries which will have value exactly 7.21 . Finite binary floating point is not able to represent 0.21 exactly, because 1/10 = 0.1 (and so 0.01 and so 0.21) requires an infinite binary expansion, the same way that in decimal, 1/7 requires an infinite decimal expansion.
You need to test for values that are "close enough" to 7.21 for your purpose. abs(x-7.21) < tolerance for some positive tolerance such as 1E-10

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by