compare two columns and their corresponding values from two different excel files

5 ビュー (過去 30 日間)
LeoAiE
LeoAiE 2021 年 4 月 6 日
コメント済み: LeoAiE 2021 年 4 月 7 日
Hi,
I’m trying to compare two columns and their corresponding values from two different excel files. I want to know what values from column one in spreadsheet one matches column one in spreadsheet two but their corresponding values are not the same. And I want to print those different values.
Below I have a list of countries and their corresponding cities, I mismatched some of them for example ALGERIA and it’s corresponding is ALGIERS but in the second document it has TIRANA as corresponding city. I want to show that difference. I used ismember function but I don’t think this is an accurate approach.
Data = readtable("Data.xlsx")
Data2 = readtable("Data2.xlsx")
Matches = ismember(Data.country,Data2.country) & ~ismember(Data.city,Data2.city)
  2 件のコメント
Bob Thompson
Bob Thompson 2021 年 4 月 6 日
編集済み: Bob Thompson 2021 年 4 月 6 日
I would think if you read the data in as string matrices, ismember can be used to compare rows. This would allow you to find all matching rows, and assume that non-matching rows are wrong.
LeoAiE
LeoAiE 2021 年 4 月 6 日
I tried that and readmarix doesn't really work with this particular case!

サインインしてコメントする。

採用された回答

dpb
dpb 2021 年 4 月 7 日
>> data1=readtable('data.xlsx');data2=readtable('Data2.xlsx');
>> setdiff(data1,data2,'rows')
ans =
3×2 table
country city
_____________ ____________
{'ALGERIA' } {'TIRANA' }
{'ARGENTINA'} {'CANBERRA'}
{'AUSTRALIA'} {'ALGIERS' }
>>

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by