find doesn't work with tables

조회 수: 30 (최근 30일)
Abdelmoumen Bacetti
Abdelmoumen Bacetti 2017년 3월 26일
댓글: Abdelmoumen Bacetti 2017년 3월 28일
hello
I'm trying to find the index vector of where appears a value in a one column of a table (not an array nor a cell).
However, "find" gives me the error shown on the snapshot.
Any ideas

채택된 답변

Guillaume
Guillaume 2017년 3월 27일
You would save yourself a lot of headache if you used the variable names instead of numerical indices for accessing the content of your tables:
big_table.UniqueWellID %instead of big_table{:, 1}
In any case, your main problem is that you want to compare char arrays, which you can't do with ==. Use strcmp to compare char arrays
find(strcmp(big_table.UniqueWellID, t1_u.UniqueWellID(1)))
%or if you really insist on using numerical indexing:
find(strcmp(big_table{:, 1}, t1_u{1, 1}))
  댓글 수: 1
Abdelmoumen Bacetti
Abdelmoumen Bacetti 2017년 3월 28일
That was so precise and concise answer. Thank you so much.

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

추가 답변 (2개)

Peter Perkins
Peter Perkins 2017년 3월 27일
find isn't going to work on a table, but it will work on the contents of a table. So Guillaume, is right that if you're looking for values in one variable, use dot subscripting.
Those strings, and the fact that you're searching for multiple hits for a single value, leads me to think you should be using categorical for the strings. And then when you get to the point when you need to find all the groups of rows in the table, not just one, you can easily use varfun or rowfun with that categorical as a grouping variable. Hard to give specific advice without knowing where you're headed.

Walter Roberson
Walter Roberson 2017년 3월 26일
If you are going to use variable number instead of variable name then you need to use {:,1} instead of (:,1)
  댓글 수: 2
Abdelmoumen Bacetti
Abdelmoumen Bacetti 2017년 3월 27일
I've got the same thing.
Walter Roberson
Walter Roberson 2017년 3월 27일
indexes = find(big_table{:,1} == t1_u{1,1});

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by