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