How can I insert data from different table that match a certain value?

조회 수: 2 (최근 30일)
Hello everyone, is there a function similar to VLOOKUP from excel?
I have two tables, namely "Secc" and "offset".
In the table Secc, I want to populate every row that contains the value in the "Seccion" column with the columns LI, LF and RF2 from the table "offset" that matches that value.
In the image I did that by copy/paste for the first row in table "Secc" but since I have tons of rows, I would prefer to automate the process.
I suppose I could do a VLOOKUP in Excel, but I know Matlab can handle this faster, I just don't know how.
Thanks in advance.
PD. I am uploading my files just in case you find them helpful.

채택된 답변

Sindar
Sindar 2020년 3월 23일
% find the index of the offset.FrameNumber row matching each Secc.Seccion element
[~,idx] = ismember(Secc.Seccion,offset.FrameNumber);
if any(idx == 0)
% what to do if no matching frame?
end
% create new columns of Secc, writing in the offset rows in order
Secc(:,4:6) = offset(idx,2:4);
% update the names of these new columns with the names of the offset columns
Secc.Properties.VariableNames(4:6) = offset.Properties.VariableNames(2:4);
  댓글 수: 1
Martin Zuniga
Martin Zuniga 2020년 3월 23일
At first i got an error but then I realized idx had some zeros, so I erased that part and the code worked flawlessly.
I appreciate your help!

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by