% Function Name: checkInventory % Inputs (2): - (char) a string containing the f
ID: 3537674 • Letter: #
Question
% Function Name: checkInventory
% Inputs (2): - (char) a string containing the filename of the first
% .xls file
% - (char) a string containing the filename of the second
% .xls file
% Outputs (0): None
%
% Function Description:
% You have been hired at an engineering firm, and as the newest member of
% the team, your superior has put you in charge of updating the firm's
% inventory. Your superior has supplied you with a spreadsheet that
% contains part names in the first column and part numbers in the second
% column (the first input excel) and a separate spreadsheet containing
% part numbers in the first column and quantities for each part in the
% second column (the second input excel). Further spreadsheet
% specifications can be found below:
%
% - Spreadsheet One's filename is guaranteed to be in the form
% "<something>_IN_<ID>.xls" (without the quotes) where <something> can
% be any combination of characters and <ID> will always be a
% combination of one capital letter and one number.
% - Spreadsheet Two's filename is guaranteed to be in the form
% "<something>_QU_<ID>.xls" (without the quotes) where <something> and
% <ID> are the same as that of the first spreadsheet.
% - The first row of Spreadsheet One contains the headers "Part Name" and
% "Part Number" (without the quotes) in columns 1 and 2 of the first
% row, respectively.
% - The first row of Spreadsheet Two contains the headers "Part Number"
% and "Quantity" (without the quotes) in columns 1 and 2 of the first
% row, respectively.
% - The part numbers are guaranteed to contain 7 characters, with only
% capital letters and numbers and at least one of each.
% - The values in the "Quantity" column are guaranteed to be filled with
% integers greater than or equal to zero.
% - The spreadsheets are guaranteed to have at least one part name and
% number, and no other data.
% - Part numbers found in either spreadsheet are not guaranteed to appear
% in the other.
%
% Your job is to write a function to combine the spreadsheets in the
% following way:
%
% 1. Check each part in the first spreadsheet to see if its part number
% matches any of the part numbers in the second spreadsheet.
% 2. If a match is found, the part's name, number, and quantity should be
% copied to a new spreadsheet in the first, second, and third columns,
% respectively.
% 3. If no match is found, then the string 'Part Not Found' should appear
% in the quantity column. The part name and number should be copied
% as in step 2.
% 4. The function should then write a spreadsheet called
% "<something>_FINAL_<ID>.xls" (where <something> and <ID> are the
% same as those found in the input spreadsheets and without the
% quotes) with the data found in steps 1-3. The column headers for the
% new spreadsheet should be "Part Name", "Part Number", and
% "Quantity", in that order (without the quotes).
%
% Hints:
% - Check out what strcmp() does if one or both of the inputs is a cell
% array of the same length.
% - You should only be using xlswrite() once. Remember that you can
% hold all of your information in a cell array and then use
% xlswrite() on that cell array to write the spreadsheet.
% - The strfind() function may be helpful in determining what
% <something> and <ID> are.
Explanation / Answer
%these excel ones are tougher than usual
function checkInventory(name1,name2)
b=strfind(name1,'_');
y1= name1(1:b(1)-1);
y2= name1(b(1)+1:length(name1));
name3=strcat(y1,'_FINAL_',y2);
[n,t,a1]=xlsread(name1);
[n,t,a2]=xlsread(name2);
[r1,c1]=size(a1);
[r2,c2]=size(a2);
a3{1,1}=a1{1,1};
a3{1,2}=a1{1,2};
a3{1,3}=a2{1,2};
r3=1;
for i=2:r1
flag=0;
a3{i,1}=a1{i,1};
a3{i,2}=a1{i,2};
for j=2:r2
if(strcmp(a1{i,2},a2{j,1}))
flag=1;
a3{i,3}=a2{j,2};
end
end
if flag == 0
a3{i,3}='Part Not Found';
end
end
xlswrite(name3,a3);
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.