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.

0 个评论
采纳的回答
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!