Compare two column values of 2 excel files

1 回表示 (過去 30 日間)
Rabia Hakim
Rabia Hakim 2021 年 4 月 15 日
回答済み: Tejas 2025 年 7 月 16 日
I have 2 excel files . one conatins person names and 2nd file column have also person person. I want to comapre person names one by one . based on that comparison . first file have time column. when person mae match . i need to write time column against person name in 2nd excel file.
Here are the files

回答 (1 件)

Tejas
Tejas 2025 年 7 月 16 日
Hello Rabia,
To acheive the desired workflow, follow these steps:
  • Read the contents of XLSX files into tables, using the "readtable" function.
T1 = readtable('firstFile.xlsx');
T2 = readtable('secondFile.xlsx');
  • Append an additional column to the table corresponding to the second XLSX file, inorder to store the time values.
T2.Time = strings(height(T2),1);
  • Map the names in both the tables to find the corresponding time values.
for i = 1:height(T2)
idx = find(strcmp(T2.Person{i}, T1.Name));
if ~isempty(idx)
T2.Time(i) = T1.Time{idx};
else
T2.Time(i) = ""; % "Not Found"
end
end
disp(T2);
To better understand the above workflow, refer to the following documentations:

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by