Cody

Problem 2045. Only once: cleaning up your columns

Solution 370565

Submitted on 15 Dec 2013 by Alfonso Nieto-Castanon
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
%% x = 1; y_correct = 1; y = only_once(x); assert(isequal(y,y_correct))

2   Pass
%% x = [1 0 0 1]; y_correct = [1 0 0 1]; y = only_once(x); assert(isequal(y,y_correct))

3   Pass
%% x = [0 0 1 1 0;0 1 1 0 0;0 0 0 0 1]; y_correct = [0 0 1 1 0;0 1 0 0 0;0 0 0 0 1]; y = only_once(x); assert(isequal(y,y_correct))

4   Pass
%% x = randi(2,10,10)-1; y = only_once(x); assert(all(sum(y,1)==any(y,1)))

5   Pass
%% x = randi(2,1,100)-1; y = only_once(x); assert(all(sum(y,1)==any(y,1)))

6   Pass
%% x = randi(2,10,1)-1; y = only_once(x); assert(all(sum(y,1)==any(y,1)))

Suggested Problems

More from this Author31

Community Treasure Hunt

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

Start Hunting!