Cody

# Problem 2607. Generate Square Wave

Solution 2272563

Submitted on 11 May 2020 by Joshua Sonn
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
len = 10; num_cycle = 5; duty = 0.5; y_correct = [1 0 1 0 1 0 1 0 1 0]; assert(isequal(genSq(len,num_cycle,duty),y_correct))

y = 0 1 2 3 4 5 6 7 8 9 y = 0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 4.5000 y = 1×10 logical array 1 0 1 0 1 0 1 0 1 0

2   Pass
len = 20; num_cycle = 4; duty = .2; y_correct = [1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0]; assert(isequal(genSq(len,num_cycle,duty),y_correct))

y = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 y = Columns 1 through 17 0 0.2000 0.4000 0.6000 0.8000 1.0000 1.2000 1.4000 1.6000 1.8000 2.0000 2.2000 2.4000 2.6000 2.8000 3.0000 3.2000 Columns 18 through 20 3.4000 3.6000 3.8000 y = 1×20 logical array 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0

3   Pass
len = 10; num_cycle = 1; duty = 1; y_correct = ones(1,10); assert(isequal(genSq(len,num_cycle,duty),y_correct))

y = 0 1 2 3 4 5 6 7 8 9 y = 0 1 2 3 4 5 6 7 8 9 y = 1×10 logical array 1 1 1 1 1 1 1 1 1 1

4   Pass
len = 10; num_cycle = 1; duty = 0; y_correct = zeros(1,10); assert(isequal(genSq(len,num_cycle,duty),y_correct))

y = 0 1 2 3 4 5 6 7 8 9 y = 0 0 0 0 0 0 0 0 0 0 y = 0 0 0 0 0 0 0 0 0 0

5   Pass
txt = fileread('genSq.m'); assert(isempty(strfind(txt,'for'))); assert(isempty(strfind(txt,'while'))); assert(isempty(strfind(txt,'if')));

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!