In: Computer Science
Match a student number: Write a function MatchStudentNumber that takes a student number from the StudentNumber column in the reference table and determine if there is a match with a student number from the StudentNumber column in the second table. The output is a logical flag that is true if at least one match was found, and integer array that points to rows in table where a match occurred. Note that the function should find all matches.
function [iflag, matchPosition] =MatchStudentNumber(studentnumber, tableToFindRecord)
% Inputs: studentnumber: studentname from StudentNumber column in the reference table
% tableToFindRecord: table of any size
% Outputs: iflag: logical flag that is true if at least one match was found, and
% matchPosition: integer array that points to rows in table where matches occurred.
%MATLAB
end
function [iflag, matchPosition]
=MatchStudentNumber(studentnumber, tableToFindRecord)
% Matlab function that matches the studentnumber in table
tableToFindRecord and outputs all the rows where studentnumber is
present in tableToFindRecord
% Inputs: studentnumber: studentname from StudentNumber column in
the reference table
% tableToFindRecord: table of any size
% Outputs: iflag: logical flag that is true if at least one match
was found, and
% matchPosition: integer array that points to rows in table where
matches occurred.
% Assuming studentnumber in reference table and tableToFindRecord
is of
% numeric type
iflag = false; % set iflag to false at the start
matchPosition = 0;
k = 1; % next Index of matchPosition
% loop over the rows of table tableToFindRecord
for i=1:length(tableToFindRecord.StudentNumber)
% if ith studentNumber in tableToFindRecord = studentnumber
if(tableToFindRecord.StudentNumber(i) == studentnumber)
iflag = true; % set iflag to true
matchPosition(k) = i; % insert row i in matchPosition
k = k + 1; % increment k by 1
end
end
end