Cody

# Problem 2803. Split up vector or matrix delimited by NaNs

Solution 610058

Submitted on 2 Apr 2015 by Yuan
• Size: 14
• 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
%% x = 7; c_correct = {7}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = [7]

2   Pass
%% x = nan; assert(isempty(split_nan_delimited(x)) && iscell(split_nan_delimited(x)))

c = {} c = {}

3   Pass
%% x = [nan; 7; 0; nan]; c_correct = {[7; 0]}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = {} c = [2x1 double] c = [2x1 double]

4   Pass
%% x = rand(66,1); c_correct = {x}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = [66x1 double]

5   Pass
%% x = (1:20)'; c_correct = {x}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = [20x1 double]

6   Pass
%% x = [1 76 -inf 0 3 nan 16 7 2 1 0 0 inf 13]'; c_correct = {x(1:5) x(7:end)}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = [5x1 double] c = [5x1 double] c = [5x1 double] c = [5x1 double] [8x1 double]

7   Pass
%% x = (1:34)'; x([6:7 19:21 30]) = nan; c_correct = {x(1:5) x(8:18) x(22:29) x(31:end)}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = [5x1 double] c = [5x1 double] c = [5x1 double] c = [5x1 double] c = [5x1 double] [11x1 double] c = [5x1 double] [11x1 double] c = [5x1 double] [11x1 double] c = [5x1 double] [11x1 double] c = [5x1 double] [11x1 double] c = [5x1 double] [11x1 double] [8x1 double] c = [5x1 double] [11x1 double] [8x1 double] c = [5x1 double] [11x1 double] [8x1 double] c = [5x1 double] [11x1 double] [8x1 double] [4x1 double]

8   Pass
%% x = 10*rand(55,6)-5; x([1:2 6 13:15 40],:) = nan; c_correct = {x(3:5,:) x(7:12,:) x(16:39,:) x(41:end,:)}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = [3x6 double] c = [3x6 double] c = [3x6 double] c = [3x6 double] c = [3x6 double] c = [3x6 double] c = [3x6 double] c = [3x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] c = [3x6 double] [6x6 double] [24x6 double] c = [3x6 double] [6x6 double] [24x6 double] c = [3x6 double] [6x6 double] [24x6 double] c = [3x6 double] [6x6 double] [24x6 double] c = [3x6 double] [6x6 double] [24x6 double] c = [3x6 double] [6x6 double] [24x6 double] c = [3x6 double] [6x6 double] [24x6 double] c = [3x6 double] [6x6 double] [24x6 double] c = [3x6 double] [6x6 double] [24x6 double] [15x6 double]

9   Pass
%% x = [nan(4); magic(4); nan(1,4); inf(4); ones(4)]; c_correct = {magic(4) [inf(4); ones(4)]}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = [4x4 double] c = [4x4 double] c = [4x4 double] c = [4x4 double] c = [4x4 double] c = [4x4 double] c = [4x4 double] [8x4 double]

10   Pass
%% x = nan(6); c_correct = {}; assert(isempty(split_nan_delimited(x)) && iscell(split_nan_delimited(x)))

c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {}

11   Pass
%% x = [nan(4); ones(1,4)]; c_correct = {ones(1,4)}; assert(isequal(split_nan_delimited(x), c_correct ))

c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = {} c = [1x4 double]

### Community Treasure Hunt

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

Start Hunting!