Cody

# Problem 3070. Pattern Recognition 3 - Variable Unit and Array Length (including cell arrays)

Solution 1974696

Submitted on 14 Oct 2019 by kranthi kumar
• Size: 39
• This is the leading solution.
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
array = [1 2 3 4 5 1 2 3 4 5 1 2 3]; tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1

2   Pass
array = [1 2 2 1 2 1 2 2 1 2 1 2]; tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1

3   Pass
array = [1 2 1 2 2 2 1 2]; tf = 0; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0

4   Pass
array = [0.1 1 10 100 1000 10000]; array = repmat(array,[1,5]); tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1

5   Pass
array = {'c3po','r2','d2','c3po','d2','r2','c3po','r2','d2','c3po'}; tf = 0; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0

6   Pass
array = 'hi ho hi ho hi ho hi'; tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1

7   Pass
array = 'a':'z'; array = repmat(array,[1,5]); tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1

8   Pass
array = {'c3','po','r2','d2','c3','po','r2','d2','c3','po','r2','d2','c3','po','r2'}; tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1

9   Pass
array = [1 2 3 3 2 3 1 2 3 1]; tf = 0; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0

10   Pass
array = {'ab','cde','fg','ab','cbe','fg','ab','edc','fg'}; tf = 0; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0

11   Pass
array = 'abcabcabcabcabcabea'; tf = 0; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0

12   Pass
array = [1 10 100 1 100 10 1 10 100 1 10 100]; tf = 0; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0

13   Pass
array = 'hi hi him'; tf = 0; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0

14   Pass
array = {'ab','cde','fg','ab','cde','fg','ab','cde','fg'}; tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1

15   Pass
array = [ones(1,40) zeros(1,20) ones(1,40) zeros(1,20) ones(1,40)]; tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1

16   Pass
array = [-1:9 -1:4 -1:2 -1:9 -1:4 -1:2 -1:9 -1:4 -1:2 -1:9]; tf = 1; assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1 ans = logical 1

17   Pass
ind = randi(4); switch ind case 1 array = {'c3po','r2','d2','c3po','r2','d2','c3po','r2','d2','c3po'}; tf = 1; case 2 array = 'hi hi him'; tf = 0; case 3 array = [1 2 3 3 1 2 3 1 2 3]; tf = 0; case 4 array = [1 2 2 4 1 2 2 4 1]; tf = 1; end assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0

18   Pass
ind = randi(4); switch ind case 1 array = [1 2 3 3 2 3 1 2 3 1 2]; tf = 0; case 2 array = [1 10 100 1 10 1 10 100 1 10 100 1]; tf = 0; case 3 array = [1 2 2 4 5 1 2 2 4 5 1]; tf = 1; case 4 array = {'ab','cde','ab','cde','fg','ab','cde','ab','cde','fg','ab','cde','ab','cde','fg'}; tf = 1; end assert(isequal(pattern_recognition3(array),tf))

ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 0 ans = logical 1

### Community Treasure Hunt

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

Start Hunting!