Matlab Question. An engineer has collected an ordered series of N data points re
ID: 3848219 • Letter: M
Question
Matlab Question. An engineer has collected an ordered series of N data points representing the elapsed since an experiment began (at time 0) to the occurrences of a particular state. He is concerned that there has been a problem with the equipment used to automatically record the measurements and that some recording were mistakenly saved into the array multiple times (consecutively occuring of course). Write a MATLAB FUNCTION which accept this data set as an input array and then returns the following three things (in order).
a) If there was duplication (return logical true if yes and logical false if no).
b) The number of unique times consecutive duplication occurred (* note example).
c) The corrected data set with duplication removed.
* proper variable names must be used as with course guidelines.
*Example: input ==> [1 4 5 5 5 9 11 11 13 15 15 15 15 16]
output ==> true, 3, [1 4 5 9 11 13 15 16]
Explanation / Answer
Matlab code:
function [bool,occur,modify] = duplicates(original)
occur = 0;
modify = unique(original);
if(size(original,2) == size(modify,2))
bool = false;
else
bool = true;
end
for i = 2:size(original,2)
if(original(i-1) == original(i) & original(i-1) != original(i-2))
occur = occur + 1;
end
end
end
Sample Output: