Cody

Problem 2010. Wrap a vector, but insert NaN's at the wrap-positions.

Solution 361151

Submitted on 28 Nov 2013 by Norbert Marwan
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:20; m = 3; y = wrapnan(x,m); y_correct = [1 2 nan 0 1 2 nan 0 1 2 nan 0 1 2 nan 0 1 2 nan 0 1 2 nan 0 1 2]; assert(isequaln(y,y_correct)) filetext = fileread('wrapnan.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp* command is forbidden'); assert(isempty(strfind(filetext, 'eval')),'eval* command is forbidden'); assert(isempty(strfind(filetext, 'inline')),'inline command is forbidden');

dd = 3 6 9 12 15 18 ans = Columns 1 through 16 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 Columns 17 through 20 2 0 1 2 ans = Columns 1 through 16 1 2 NaN 0 1 2 0 1 2 0 1 2 0 1 2 0 Columns 17 through 21 1 2 0 1 2 ans = Columns 1 through 16 1 2 NaN 0 1 2 NaN 0 1 2 0 1 2 0 1 2 Columns 17 through 22 0 1 2 0 1 2 ans = Columns 1 through 16 1 2 NaN 0 1 2 NaN 0 1 2 NaN 0 1 2 0 1 Columns 17 through 23 2 0 1 2 0 1 2 ans = Columns 1 through 16 1 2 NaN 0 1 2 NaN 0 1 2 NaN 0 1 2 NaN 0 Columns 17 through 24 1 2 0 1 2 0 1 2 ans = Columns 1 through 16 1 2 NaN 0 1 2 NaN 0 1 2 NaN 0 1 2 NaN 0 Columns 17 through 25 1 2 NaN 0 1 2 0 1 2 ans = Columns 1 through 16 1 2 NaN 0 1 2 NaN 0 1 2 NaN 0 1 2 NaN 0 Columns 17 through 26 1 2 NaN 0 1 2 NaN 0 1 2

2   Pass
%% x = [1 50 95 105 195 205 190 310 290 250 201 10]; m = 100; y = wrapnan(x,m); y_correct = [1 50 95 nan 5 95 nan 5 nan 90 nan 10 nan 90 50 1 nan 10]; assert(isequaln(y,y_correct))

dd = 4 6 7 8 9 12 ans = 1 50 95 5 95 5 90 10 90 50 1 10 ans = 1 50 95 NaN 5 95 5 90 10 90 50 1 10 ans = 1 50 95 NaN 5 95 NaN 5 90 10 90 50 1 10 ans = 1 50 95 NaN 5 95 NaN 5 NaN 90 10 90 50 1 10 ans = 1 50 95 NaN 5 95 NaN 5 NaN 90 NaN 10 90 50 1 10 ans = Columns 1 through 16 1 50 95 NaN 5 95 NaN 5 NaN 90 NaN 10 NaN 90 50 1 Column 17 10 ans = Columns 1 through 16 1 50 95 NaN 5 95 NaN 5 NaN 90 NaN 10 NaN 90 50 1 Columns 17 through 18 NaN 10

3   Pass
%% x = [0.25 0.45 0.80 0.90 1.25 0.60 0.10 0.20 1.70 1.60 1.50 1.80 1.40 0.10]; m = 0.5; y = wrapnan(x,m); y_correct = [0.25 0.45 NaN 0.30 0.40 NaN 0.25 NaN 0.10 NaN 0.10 0.20 NaN 0.20 0.10 0.00 0.30 NaN 0.40 NaN 0.10]; assert(isequaln(roundn(y,2),roundn(y_correct,2)))

dd = 3 5 6 7 9 13 14 ans = Columns 1 through 10 0.2500 0.4500 0.3000 0.4000 0.2500 0.1000 0.1000 0.2000 0.2000 0.1000 Columns 11 through 14 0 0.3000 0.4000 0.1000 ans = Columns 1 through 10 0.2500 0.4500 NaN 0.3000 0.4000 0.2500 0.1000 0.1000 0.2000 0.2000 Columns 11 through 15 0.1000 0 0.3000 0.4000 0.1000 ans = Columns 1 through 10 0.2500 0.4500 NaN 0.3000 0.4000 NaN 0.2500 0.1000 0.1000 0.2000 Columns 11 through 16 0.2000 0.1000 0 0.3000 0.4000 0.1000 ans = Columns 1 through 10 0.2500 0.4500 NaN 0.3000 0.4000 NaN 0.2500 NaN 0.1000 0.1000 Columns 11 through 17 0.2000 0.2000 0.1000 0 0.3000 0.4000 0.1000 ans = Columns 1 through 10 0.2500 0.4500 NaN 0.3000 0.4000 NaN 0.2500 NaN 0.1000 NaN Columns 11 through 18 0.1000 0.2000 0.2000 0.1000 0 0.3000 0.4000 0.1000 ans = Columns 1 through 10 0.2500 0.4500 NaN 0.3000 0.4000 NaN 0.2500 NaN 0.1000 NaN Columns 11 through 19 0.1000 0.2000 NaN 0.2000 0.1000 0 0.3000 0.4000 0.1000 ans = Columns 1 through 10 0.2500 0.4500 NaN 0.3000 0.4000 NaN 0.2500 NaN 0.1000 NaN Columns 11 through 20 0.1000 0.2000 NaN 0.2000 0.1000 0 0.3000 NaN 0.4000 0.1000 ans = Columns 1 through 10 0.2500 0.4500 NaN 0.3000 0.4000 NaN 0.2500 NaN 0.1000 NaN Columns 11 through 20 0.1000 0.2000 NaN 0.2000 0.1000 0 0.3000 NaN 0.4000 NaN Column 21 0.1000

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!