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

In the editor in MATLAB (or Octave-online) open a new file and write the functio

ID: 3607630 • Letter: I

Question

In the editor in MATLAB (or Octave-online) open a new file and write the function tokenizeSignal(binary_signal) which takes the binary signal from Part 1 and counts how many 0's and 1's appear in sequence. The output should be a 2D array where column 1 is how many appear and column 2 is which token it is (0 or 1). Save the file as ‘tokenizeSignal.m’

For example:

>> arr = [0; 0; 0; 1; 1; 1; 0];

>> tokenizeSignal(arr)

ans =

     3     0

     3     1

     1     0

Hints: this can be done with or without loops. To do it without any loops you need to use array slicing, concatenation and the find and diff functions in MATLAB. Try out the following with the example arr:

>> diff(arr)

>> diff([arr; -1])

>> find(diff([arr; -1]))

>> diff(find(diff([arr; -1])))

Submit your function to the quiz server for grading.

Explanation / Answer

%working function in Octave online , if you get any problem please reply.function %will return 2D vector so you call as %ans= tokenizeSignal(arr) where arr is input array function ans= tokenizeSignal(binary_signal) y=find(diff([binary_signal;-1])); %find non zero index from diff with next element of %binary_signal z=diff(y); %count number between two non zero difference s=binary_signal(y); %find out the value at non zero diff index t=[y(1);z]; %how many appear ans=[t s]; %this is 2d array as asked end