Algorithm: Initialize empty token matrix Initialize count variable Initialize current token Loop over binary signal If the next token matches the current token, update the count If the next token does not match, append the current token and count to token matrix, rest the count and update current token At the end loop, append last token and count to token matrix

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question
100%

Algorithm:

Initialize empty token matrix

Initialize count variable

Initialize current token

Loop over binary signal

If the next token matches the current token, update the count

If the next token does not match, append the current token and count to token matrix, rest the count and update current token

At the end loop, append last token and count to token matrix

Define a function named binary_to_tokens which accepts a column vector of binary values (O's and 1's) and counts how many O's and 1's appear in sequence. The function should return a
matrix where column 1 contains the token value (0 or 1) and column 2 contains how many appear in sequence.
You can use these tests to debug your function in MATLAB or Octave:
Test
Result
binary_signal = [ 1; 1; 1; 1; 0; 0; 1; 1; 1; O; 0; 0; O];
[1 4; 0 2; 1 3; 0 4]
disp(binary_to_tokens (binary_signal) )
binary_signal = [ 0; 0; 1; 1; 1; 0; 1; 1; 1; 0; 0; 0; 0;0];
[0 2; 1 3; 0 1; 1 3; 0 5]
disp(binary_to_tokens (binary_signal) )
Transcribed Image Text:Define a function named binary_to_tokens which accepts a column vector of binary values (O's and 1's) and counts how many O's and 1's appear in sequence. The function should return a matrix where column 1 contains the token value (0 or 1) and column 2 contains how many appear in sequence. You can use these tests to debug your function in MATLAB or Octave: Test Result binary_signal = [ 1; 1; 1; 1; 0; 0; 1; 1; 1; O; 0; 0; O]; [1 4; 0 2; 1 3; 0 4] disp(binary_to_tokens (binary_signal) ) binary_signal = [ 0; 0; 1; 1; 1; 0; 1; 1; 1; 0; 0; 0; 0;0]; [0 2; 1 3; 0 1; 1 3; 0 5] disp(binary_to_tokens (binary_signal) )
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning