Cody

# Problem 576. Return elements unique to either input

Solution 373084

Submitted on 20 Dec 2013 by Robert
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
%% a = [1 2 3 4 5]; b = [2 3 4 5 6]; y_correct = [1 6]; assert(isequal(vector_diff(a,b),y_correct))

ra = 1 ca = 5 rb = 1 cb = 5 commons = [] ya = 1 2 3 4 5 yb = 2 3 4 5 6 commons = 2 commons = 2 3 commons = 2 3 4 commons = 2 3 4 5 commons = 2 3 4 5 ya = 1 3 4 5 yb = 3 4 5 6 ya = 1 4 5 yb = 4 5 6 ya = 1 5 yb = 5 6 ya = 1 yb = 6 y = 1 6

2   Pass
%% a = 10:-2:0; b = 1:2:11; y_correct = 0:11; assert(isequal(vector_diff(a,b),y_correct))

ra = 1 ca = 6 rb = 1 cb = 6 commons = [] ya = 0 2 4 6 8 10 yb = 1 3 5 7 9 11 commons = Empty matrix: 0-by-1 y = 0 1 2 3 4 5 6 7 8 9 10 11

3   Pass
%% a=magic(5); b=magic(6); y_correct = 26:36; assert(isequal(vector_diff(a,b),y_correct))

ra = 5 ca = 5 rb = 6 cb = 6 commons = [] ya = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 25 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 36 33 34 35 36 commons = 1 commons = 1 2 commons = 1 2 3 commons = 1 2 3 4 commons = 1 2 3 4 5 commons = 1 2 3 4 5 6 commons = 1 2 3 4 5 6 7 commons = 1 2 3 4 5 6 7 8 commons = 1 2 3 4 5 6 7 8 9 commons = 1 2 3 4 5 6 7 8 9 10 commons = 1 2 3 4 5 6 7 8 9 10 11 commons = 1 2 3 4 5 6 7 8 9 10 11 12 commons = 1 2 3 4 5 6 7 8 9 10 11 12 13 commons = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 commons = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 commons = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Column 17 17 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 18 17 18 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 19 17 18 19 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 20 17 18 19 20 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 21 17 18 19 20 21 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 22 17 18 19 20 21 22 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 23 17 18 19 20 21 22 23 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 24 17 18 19 20 21 22 23 24 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 25 17 18 19 20 21 22 23 24 25 commons = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 25 17 18 19 20 21 22 23 24 25 ya = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 24 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 32 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Columns 33 through 35 34 35 36 ya = Columns 1 through 16 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Columns 17 through 23 19 20 21 22 23 24 25 yb = Columns 1 through 16 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Columns 17 through 32 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Columns 33 through 34 35 36 ya = Columns 1 through 16 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Columns 17 through 22 20 21 22 23 24 25 yb = Columns 1 through 16 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Columns 17 through 32 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Column 33 36 ya = Columns 1 through 16 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Columns 17 through 21 21 22 23 24 25 yb = Columns 1 through 16 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Columns 17 through 32 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ya = Columns 1 through 16 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Columns 17 through 20 22 23 24 25 yb = Columns 1 through 16 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Columns 17 through 31 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ya = Columns 1 through 16 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Columns 17 through 19 23 24 25 yb = Columns 1 through 16 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Columns 17 through 30 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ya = Columns 1 through 16 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Columns 17 through 18 24 25 yb = Columns 1 through 16 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Columns 17 through 29 24 25 26 27 28 29 30 31 32 33 34 35 36 ya = Columns 1 through 16 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Column 17 25 yb = Columns 1 through 16 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Columns 17 through 28 25 26 27 28 29 30 31 32 33 34 35 36 ya = 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Columns 17 through 27 26 27 28 29 30 31 32 33 34 35 36 ya = 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 26 27 28 29 30 31 32 33 34 35 36 ya = 12 13 14 15 16 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Columns 17 through 25 28 29 30 31 32 33 34 35 36 ya = 13 14 15 16 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 17 through 24 29 30 31 32 33 34 35 36 ya = 14 15 16 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Columns 17 through 23 30 31 32 33 34 35 36 ya = 15 16 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Columns 17 through 22 31 32 33 34 35 36 ya = 16 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Columns 17 through 21 32 33 34 35 36 ya = 17 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 17 through 20 33 34 35 36 ya = 18 19 20 21 22 23 24 25 yb = Columns 1 through 16 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Columns 17 through 19 34 35 36 ya = 19 20 21 22 23 24 25 yb = Columns 1 through 16 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Columns 17 through 18 35 36 ya = 20 21 22 23 24 25 yb = Columns 1 through 16 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Column 17 36 ya = 21 22 23 24 25 yb = 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ya = 22 23 24 25 yb = 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ya = 23 24 25 yb = 23 24 25 26 27 28 29 30 ...

4   Pass
%% a=(10:100)'; b=11:100; y_correct = 10; assert(isequal(vector_diff(a,b),y_correct))

ra = 91 ca = 1 rb = 1 cb = 90 commons = [] ya = Columns 1 through 16 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Columns 17 through 32 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 Columns 33 through 48 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 Columns 49 through 64 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 Columns 65 through 80 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 Columns 81 through 91 90 91 92 93 94 95 96 97 98 99 100 yb = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 48 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 Columns 49 through 64 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 Columns 65 through 80 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 Columns 81 through 90 91 92 93 94 95 96 97 98 99 100 commons = 11 commons = 11 12 commons = 11 12 13 commons = 11 12 13 14 commons = 11 12 13 14 15 commons = 11 12 13 14 15 16 commons = 11 12 13 14 15 16 17 commons = 11 12 13 14 15 16 17 18 commons = 11 12 13 14 15 16 17 18 19 commons = 11 12 13 14 15 16 17 18 19 20 commons = 11 12 13 14 15 16 17 18 19 20 21 commons = 11 12 13 14 15 16 17 18 19 20 21 22 commons = 11 12 13 14 15 16 17 18 19 20 21 22 23 commons = 11 12 13 14 15 16 17 18 19 20 21 22 23 24 commons = 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 commons = 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Column 17 27 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 18 27 28 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 19 27 28 29 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 20 27 28 29 30 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 21 27 28 29 30 31 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 22 27 28 29 30 31 32 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 23 27 28 29 30 31 32 33 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 24 27 28 29 30 31 32 33 34 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 25 27 28 29 30 31 32 33 34 35 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 26 27 28 29 30 31 32 33 34 35 36 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 27 27 28 29 30 31 32 33 34 35 36 37 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 28 27 28 29 30 31 32 33 34 35 36 37 38 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 29 27 28 29 30 31 32 33 34 35 36 37 38 39 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 30 27 28 29 30 31 32 33 34 35 36 37 38 39 40 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 31 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Column 33 43 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 34 43 44 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 35 43 44 45 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 36 43 44 45 46 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 37 43 44 45 46 47 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 38 43 44 45 46 47 48 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 39 43 44 45 46 47 48 49 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 40 43 44 45 46 47 48 49 50 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 41 43 44 45 46 47 48 49 50 51 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 42 43 44 45 46 47 48 49 50 51 52 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 43 43 44 45 46 47 48 49 50 51 52 53 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 44 43 44 45 46 47 48 49 50 51 52 53 54 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 17 through 32 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 33 through 45 43 44 45 46 47 48 49 50 51 52 53 54 55 commons = Columns 1 through 16 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Columns 1...

5   Pass
%% a=magic(3)-1.5; b=[]; y_correct = -0.5:7.5; assert(isequal(vector_diff(a,b),y_correct))

ra = 3 ca = 3 rb = 0 cb = 0 commons = [] ya = -0.5000 0.5000 1.5000 2.5000 3.5000 4.5000 5.5000 6.5000 7.5000 yb = Empty matrix: 1-by-0 commons = Empty matrix: 0-by-1 y = -0.5000 0.5000 1.5000 2.5000 3.5000 4.5000 5.5000 6.5000 7.5000

6   Pass
%% a=zeros(5); b=ones(3); y_correct=[0 1]; assert(isequal(vector_diff(a,b),y_correct))

ra = 5 ca = 5 rb = 3 cb = 3 commons = [] ya = Columns 1 through 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 17 through 25 0 0 0 0 0 0 0 0 0 yb = 1 1 1 1 1 1 1 1 1 commons = Empty matrix: 0-by-1 y = 0 1

7   Pass
%% forbidden = '(regexp)'; assert(isempty(regexp(evalc('type vector_diff'),forbidden)));