Finding discrepancies between two spreadsheets in MATLAB
이전 댓글 표시
Good evening! I am currently trying to work on writing a script that will allow me to find discrepancies between two spreadsheets (.xls, .csv, .xlsm).
Currently, the two spreadsheets have thousands of rows but a set number of columns. In spreadsheet 1, there is a column called "Issue Key" that corresponds to another column in spreadsheet 2 that is labeled "Cross-reference." Is there a way to import the two spreadsheets and have MATLAB re-order the tables based on this similarity?
My current code reads the XLS and CVS files into two separate variables data1 and data2. One of the issues I notice is that I don't know how to declare the first row of each variable as the variable name. I'm not exactly sure if I'm even on the right path at this point so I'm very eager to listen to suggestions. I'm very new to this coding thing, aha!
This is my current code:
clc;
clear;
close all;
[baseName, folder] = uigetfile({'*.xls'; '*.csv'}, 'Select the RTC Export:');
filename = fullfile(folder, baseName);
% Reads data in from selected file and loads them into num (only numeric),
% txt (only string) and raw (all data)
[num, txt, raw] = xlsread(filename);
data = [raw(:,1) raw(:,2) raw(:,5) raw(:,11) raw(:,12)];
tabledata = cell2table(data);
[baseName, folder] = uigetfile({'*.xls'; '*.csv'}, 'Select the JIRA Export:');
filename = fullfile(folder, baseName);
[num, txt, raw] = xlsread(filename);
data2 = [raw(:,3) raw(:,5) raw(:,2) raw(:,1)];
tabledata2 = cell2table(data2);
댓글 수: 9
Rik
2020년 1월 21일
Can you provide small sample files? You can include them as a zip. And can you provide an example of the intended output?
Mohammad Sami
2020년 1월 21일
You can use the readtable function to import your data. You can use ismember function to compare the two columns. Use the index output from ismember to reorder your data in the same order, or perhaps use the sort function to sort both tables by the desired variable.
Thanh Nguyen
2020년 1월 21일
Walter Roberson
2020년 1월 21일
innerjoin() ?
Thanh Nguyen
2020년 1월 21일
Walter Roberson
2020년 1월 21일
T1 = readtable('testtable1.xlsx');
T2 = readtable('testtable2.xlsx');
T3 = innerjoin(T1, T2, 'leftkeys', 'IssueID', 'rightkeys', 'CrossReference');
"IssueKey" contains character arrays such as 'B-1', 'B-2' while CrossReference are numeric interger values such as 316216, 301258. Since there are no repeats within either of the columns from either spreadsheet that you attached, it's unclear how they pair with each other.
If the rows of both spread sheets are not in the same order, how do we pair the B-1 values with the 316216 values?
Thanh Nguyen
2020년 1월 21일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!