I am looking for a way to include duplicates into ismember function

조회 수: 16 (최근 30일)
Hi All,
I am looking for a solution to include duplicates into the ismember function. I have two tables, Table 1 with ages in one column, and an isotope value in the other column, and Table 2 just with ages. The ages in both tables differ, and I am looking for a way to find the closest fit of the ages in Table 1 for the ages in Table 2 to relate isotope values from Table 1 to ages in Table 2. For that, I have used:
b = interp1(a,a,y, 'nearest'); %where a=age Table 1 and y=age Table 2
To find the related isotope values I have used:
O = Osw(ismember(a,b)); %where Osw=isotope values from Table 1
This gives me all isotope values for the common ages in a and b, but just once, which gives me a shorter array than the length of the input tables since those have multiple values that are the same. Is there any way that the ismember function includes multiples/duplicates ,or does the operation for each row individually (I tried adding the "rows" command)? Every suggestion on how to solve this would be greatly appreciated. If anything should be unclear just ask, I'll try to explain it better. I hope someone who is more proficient with matlab can help me with this.
Cheers,
Laurenz

채택된 답변

Bruno Luong
Bruno Luong 2022년 4월 25일
편집: Bruno Luong 2022년 4월 25일
Why use ismember at all (at least in that way)?
O = Osw( interp1(a,1:length(a),y, 'nearest'))
  댓글 수: 2
Laurenz Boettger
Laurenz Boettger 2022년 4월 25일
Hi Bruno,
Thank you so much the solution works perfectly, and you are absolutly right ismember wasn't necessary in this case.
Bruno Luong
Bruno Luong 2022년 4월 25일
If you insist on using ismember, reverse the arguments
b = interp1(a,a,y, 'nearest');
[~,ia] = ismember(b,a);
O = Osw(ia);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by