Cody

# Problem 980. Unique values without using UNIQUE function

Solution 2044529

Submitted on 3 Dec 2019 by Asif Newaz
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
filetext = fileread('your_fcn_name.m') assert(isempty(strfind(filetext, 'unique'))) assert(isempty(strfind(filetext, 'stable'))) A = [9 2 9 5]; assert(isequal(your_fcn_name(A),unique(A,'stable')))

filetext = 'function y = your_fcn_name(x) a =length(x) k=1; z=x; for i=1:a b=find(z==x(i)) if numel(b)==1 y(k)=z(b) k=k+1; z(b)=[] elseif numel(b)>1 y(k)=z(b(1)) k=k+1; z(b)=[] end end end %This code written by profile_id 16549154 ' a = 4 b = 1 3 y = 9 z = 2 5 b = 1 y = 9 2 z = 5 b = [] b = 1 y = 9 2 5 z = 1×0 empty double row vector

2   Pass
x = [42 1 1 1 42 17 17]; assert(isequal(your_fcn_name(x),unique(x,'stable')))

a = 7 b = 1 5 y = 42 z = 1 1 1 17 17 b = 1 2 3 y = 42 1 z = 17 17 b = 1×0 empty double row vector b = 1×0 empty double row vector b = 1×0 empty double row vector b = 1 2 y = 42 1 17 z = 1×0 empty double row vector b = 1×0 empty double row vector

3   Pass
x = rand(1,25); assert(isequal(your_fcn_name(x),unique(x,'stable')))

a = 25 b = 1 y = 0.9217 z = Columns 1 through 18 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 Columns 19 through 24 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 z = Columns 1 through 18 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 Columns 19 through 23 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 z = Columns 1 through 18 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 Columns 19 through 22 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 z = Columns 1 through 18 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 Columns 19 through 21 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 z = Columns 1 through 18 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 Columns 19 through 20 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 z = Columns 1 through 18 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 Column 19 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 z = 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 z = 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 z = 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 z = 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 z = 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 z = 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 z = 0.0397 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 z = 0.2932 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 z = 0.5558 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 z = 0.8991 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 z = 0.2048 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 z = 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = Columns 1 through 18 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 Column 19 0.4593 z = 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = Columns 1 through 18 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 Columns 19 through 20 0.4593 0.4608 z = 0.0041 0.3481 0.3058 0.8998 0.7141 b = 1 y = Columns 1 through 18 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 Columns 19 through 21 0.4593 0.4608 0.0041 z = 0.3481 0.3058 0.8998 0.7141 b = 1 y = Columns 1 through 18 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 Columns 19 through 22 0.4593 0.4608 0.0041 0.3481 z = 0.3058 0.8998 0.7141 b = 1 y = Columns 1 through 18 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 Columns 19 through 23 0.4593 0.4608 0.0041 0.3481 0.3058 z = 0.8998 0.7141 b = 1 y = Columns 1 through 18 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 Columns 19 through 24 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 z = 0.7141 b = 1 y = Columns 1 through 18 0.9217 0.9733 0.8018 0.5465 0.2001 0.3442 0.4118 0.1947 0.6534 0.3786 0.3794 0.0778 0.0773 0.0397 0.2932 0.5558 0.8991 0.2048 Columns 19 through 25 0.4593 0.4608 0.0041 0.3481 0.3058 0.8998 0.7141 z = 1×0 empty double row vector