Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB : An engineer has collected an ordered series of N data points representi

ID: 3848202 • Letter: M

Question

MATLAB:

An engineer has collected an ordered series of N data points representing the elapsed time 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 recordings were mistakenly saved into the array multiple times (consecutively occurring 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,

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

The code is given below:

R = input('Input your vector:');

l= length(R);
a=[];
b='false';
c=0;
flag=0;
i=1;
while(i<l)
for j=(i+1):l
if(R(i)==R(j))
b='true';
flag=1;
continue;
else
break;
end
end
if(flag==1)
c=c+1;
i=j;
else
i=i+1;
end
end
a(1)=R(1);
j=2;
for i=1:l-1
if(R(i)~=R(i+1))
a(j)=R(i+1);
j=j+1;
end
end
disp(b);
disp(c);
disp(a);