matching based on a condtion cell table

조회 수: 1 (최근 30일)
sensation
sensation 2017년 10월 19일
댓글: Cam Salzberger 2017년 10월 19일
Hi, I have a cell with:
'ABA1'
'ABO1'
'ACE3'
'ACE4'
Then I have a table with:
'AAYUC01' 3.7
'ABA1' 4.5
'ABA2' 4.5
'ABENVD1' 4360
'ABO1' 7521.3
How I can find the matching between my table and cell so that result is:
'ABA1' 4.5
'ABO1' 7521.3
Thanks a lot!
  댓글 수: 1
Jan
Jan 2017년 10월 19일
It is easier to write an answer, if you provide the inputs, such that they can be used by copy&paste. Otherwise all readers have to do this by their own and remove the tedious empty lines.

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

채택된 답변

Cam Salzberger
Cam Salzberger 2017년 10월 19일
편집: Cam Salzberger 2017년 10월 19일
Hello,
I believe that ismember is your friend here. It will produce a logical array indicating which rows' elements are contained within your first set. You can then use that to index into the table.
C = {'A' ; 'B' ; 'C'};
T = table({'A' ; 'X' ; 'C' ; 'Y'}, (1:4).');
whichRows = ismember(T{:, 1}, C);
T(whichRows, :)
This is just a simple example, but easily adapted to your data.
-Cam
  댓글 수: 2
sensation
sensation 2017년 10월 19일
Hi Cam,
I was trying to do that but have always the eror msg eventhough I have C being 205x1 cell and T being 900x2 table:
Error using cell/ismember (line 34) Input A of class cell and input B of class cell must be cell arrays of strings, unless one is a string.
Cam Salzberger
Cam Salzberger 2017년 10월 19일
What I thought you wanted was only the rows of the table who have their first column values present in the cell array. Which means you want to have the table as the first input argument to ismember.
If it's giving you an error about "cell/ismember", that means your first input argument is a cell array. Try switching them.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by