Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 229133

Submitted on 10 Apr 2013 by Jean-Marie SAINTHILLIER

Correct

72Size
Leading solution size is 48.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
C =   [1     1     1     0
       0     0     0     0
       0     1     0     1];
K = 2;
[A,B] = ebmf(C,K);
assert(isequal(A*B,C))
assert(isequal(unique(A),[0; 1]))
assert(isequal(unique(B),[0; 1]))
assert(all(size(A)==[size(C,1),K]))
assert(all(size(B)==[K,size(C,2)]))

                    
2
Pass
 
%%
C = [1     0     0
     1     0     0
     1     1     0];
K = 3;
[A,B] = ebmf(C,K);
assert(isequal(A*B,C))
assert(isequal(unique(A),[0; 1]))
assert(isequal(unique(B),[0; 1]))
assert(all(size(A)==[size(C,1),K]))
assert(all(size(B)==[K,size(C,2)]))

                    
3
Pass
 
%%
C = [0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     1     0     0     0     1     1     1     0     1     0
     1     0     0     0     1     1     1     0     1     0
     1     0     0     0     1     1     1     0     1     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0];
K = 1;
[A,B] = ebmf(C,K);
assert(isequal(A*B,C))
assert(isequal(unique(A),[0; 1]))
assert(isequal(unique(B'),[0; 1]))
assert(all(size(A)==[size(C,1),K]))
assert(all(size(B)==[K,size(C,2)]))

                    
4
Pass
 
%% Added another small test case
C = [1     0     1
     1     1     1
     0     1     0];
K = 2;
[A,B] = ebmf(C,K);
assert(isequal(A*B,C))
assert(isequal(unique(A),[0; 1]))
assert(isequal(unique(B'),[0; 1]))
assert(all(size(A)==[size(C,1),K]))
assert(all(size(B)==[K,size(C,2)]))

                    
5
Pass
 
%% A degenerate problem
C = [0     0     1
     0     0     0
     0     0     1];
K = 2;
[A,B] = ebmf(C,K);
assert(isequal(A*B,C))
assert(isequal(unique(A),[0; 1]))
assert(isequal(unique(B'),[0; 1]))
assert(all(size(A)==[size(C,1),K]))
assert(all(size(B)==[K,size(C,2)]))