Question

In: Computer Science

Match a student number: Write a function MatchStudentNumber that takes a student number from the StudentNumber...

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

Solutions

Expert Solution

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


Related Solutions

Write a function DIVISORS in MIPS. This function takes a positive number from the register a0...
Write a function DIVISORS in MIPS. This function takes a positive number from the register a0 and prints in a column all of its divisors including 1 and the number itself. Don't forget that printing a number and printing a character requires two different system calls. Here is an example. If the number in a0 is 6 the following output appears: 1 2 3 6
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should assume that the list is already in ascending order. The function should insert the number into the correct position of the list so that the list stays in ascending order. It should modify the list, not build a new list. It does not need to return the list, because it is modifying it.   Hint: Use a whlie loop and list methods lst = [1,3,5,7]...
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
Write a function that takes the current date and corrects the number of days, if it's...
Write a function that takes the current date and corrects the number of days, if it's wrong. The function must return true if the date passed to it is a valid date and false, if not. The main function uses the returned value to either print "Date validated", if a valid date was entered or "Invalid date entered. Changed to ", followed by the modified date. For example: if given 11/31/2020, it will produce 12/1/2020. If given 2/29/2021, it will...
Write a function num_day that takes a number in the range of 1 through 7 as...
Write a function num_day that takes a number in the range of 1 through 7 as a parameter and returns a string representing the corresponding day of the week, where 1=Monday, 2 =Tuesday, 3=Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The function should return the string "Error" if the parameter is that is outside the range of 1 through 7. You may assume that the parameter will be only numbers. Save the function...
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
Write a MATLAB function named numberWords() that takes a whole number as an argument and returns...
Write a MATLAB function named numberWords() that takes a whole number as an argument and returns a string containing the number word for the whole numbers 0 - 999. For example:  numberWords(234) would return 'two hundred thirty-four' If the input value is not a whole number between 0 - 999 then the function should return a string equivalent to 'ERROR'.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT