MATLAB Answers

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

1 view (last 30 days)
Martin Zuniga
Martin Zuniga on 22 Mar 2020
Commented: Martin Zuniga on 23 Mar 2020
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.

  0 Comments

Sign in to comment.

Accepted Answer

Sindar
Sindar on 23 Mar 2020
% 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 Comment

Martin Zuniga
Martin Zuniga on 23 Mar 2020
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!

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags

Products


Release

R2019a