Cody

Problem 71. Read a column of numbers and interpolate missing data

Solution 2270951

Submitted on 11 May 2020 by Anvitha S
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
s = { ... 'Day Temp' ' 1 1.3' ' 2 1.12' ' 3 17' ' 4 -32' ' 5 13' ' 6 4.4' ' 7 19'}; t_correct = [1.3 1.12 17 -32 13 4.4 19]; assert(isequal(read_and_interp(s),t_correct));

s = 7×6 cell array {0×0 char} {0×0 char} {'1'} {0×0 char} {0×0 char} {'1.3' } {0×0 char} {0×0 char} {'2'} {0×0 char} {0×0 char} {'1.12'} {0×0 char} {0×0 char} {'3'} {0×0 char} {0×0 char} {'17' } {0×0 char} {0×0 char} {'4'} {0×0 char} {0×0 char} {'-32' } {0×0 char} {0×0 char} {'5'} {0×0 char} {0×0 char} {'13' } {0×0 char} {0×0 char} {'6'} {0×0 char} {0×0 char} {'4.4' } {0×0 char} {0×0 char} {'7'} {0×0 char} {0×0 char} {'19' } s = 7×6 cell array {0×0 double} {0×0 double} {[1]} {0×0 double} {0×0 double} {[1.3000]} {0×0 double} {0×0 double} {[2]} {0×0 double} {0×0 double} {[1.1200]} {0×0 double} {0×0 double} {[3]} {0×0 double} {0×0 double} {[ 17]} {0×0 double} {0×0 double} {[4]} {0×0 double} {0×0 double} {[ -32]} {0×0 double} {0×0 double} {[5]} {0×0 double} {0×0 double} {[ 13]} {0×0 double} {0×0 double} {[6]} {0×0 double} {0×0 double} {[4.4000]} {0×0 double} {0×0 double} {[7]} {0×0 double} {0×0 double} {[ 19]} y = 1.3000 1.1200 17.0000 -32.0000 13.0000 4.4000 19.0000 x = 1 2 3 4 5 6 7 y = 1.3000 1.1200 17.0000 -32.0000 13.0000 4.4000 19.0000 idx = 0×1 empty double column vector idx2 = 1 2 3 4 5 6 7 y = 1.3000 1.1200 17.0000 -32.0000 13.0000 4.4000 19.0000 y = 1.3000 1.1200 17.0000 -32.0000 13.0000 4.4000 19.0000

2   Pass
s = { ... 'Day Temp' ' 1 1.3' ' 2 1.12' ' 3 17' ' 4 16' ' 5 9999' ' 6 9999' ' 7 19'}; t_correct = [1.3 1.12 17 16 17 18 19]; assert(isequal(read_and_interp(s),t_correct));

s = 7×6 cell array {0×0 char} {0×0 char} {'1'} {0×0 char} {0×0 char} {'1.3' } {0×0 char} {0×0 char} {'2'} {0×0 char} {0×0 char} {'1.12'} {0×0 char} {0×0 char} {'3'} {0×0 char} {0×0 char} {'17' } {0×0 char} {0×0 char} {'4'} {0×0 char} {0×0 char} {'16' } {0×0 char} {0×0 char} {'5'} {0×0 char} {0×0 char} {'9999'} {0×0 char} {0×0 char} {'6'} {0×0 char} {0×0 char} {'9999'} {0×0 char} {0×0 char} {'7'} {0×0 char} {0×0 char} {'19' } s = 7×6 cell array {0×0 double} {0×0 double} {[1]} {0×0 double} {0×0 double} {[1.3000]} {0×0 double} {0×0 double} {[2]} {0×0 double} {0×0 double} {[1.1200]} {0×0 double} {0×0 double} {[3]} {0×0 double} {0×0 double} {[ 17]} {0×0 double} {0×0 double} {[4]} {0×0 double} {0×0 double} {[ 16]} {0×0 double} {0×0 double} {[5]} {0×0 double} {0×0 double} {[ 9999]} {0×0 double} {0×0 double} {[6]} {0×0 double} {0×0 double} {[ 9999]} {0×0 double} {0×0 double} {[7]} {0×0 double} {0×0 double} {[ 19]} y = 1.0e+03 * 0.0013 0.0011 0.0170 0.0160 9.9990 9.9990 0.0190 x = 1 2 3 4 5 6 7 y = 1.3000 1.1200 17.0000 16.0000 NaN NaN 19.0000 idx = 5 6 idx2 = 1 2 3 4 7 y = 1.3000 1.1200 17.0000 16.0000 17.0000 18.0000 19.0000 y = 1.3000 1.1200 17.0000 16.0000 17.0000 18.0000 19.0000

3   Pass
s = { ... 'Day Temp' ' 1 -5' ' 2 19' ' 3 1' ' 4 9999' ' 5 3'}; t_correct = [-5 19 1 2 3]; assert(isequal(read_and_interp(s),t_correct));

s = 5×6 cell array {0×0 char} {0×0 char} {'1'} {0×0 char} {0×0 char} {'-5' } {0×0 char} {0×0 char} {'2'} {0×0 char} {0×0 char} {'19' } {0×0 char} {0×0 char} {'3'} {0×0 char} {0×0 char} {'1' } {0×0 char} {0×0 char} {'4'} {0×0 char} {0×0 char} {'9999'} {0×0 char} {0×0 char} {'5'} {0×0 char} {0×0 char} {'3' } s = 5×6 cell array {0×0 double} {0×0 double} {[1]} {0×0 double} {0×0 double} {[ -5]} {0×0 double} {0×0 double} {[2]} {0×0 double} {0×0 double} {[ 19]} {0×0 double} {0×0 double} {[3]} {0×0 double} {0×0 double} {[ 1]} {0×0 double} {0×0 double} {[4]} {0×0 double} {0×0 double} {[9999]} {0×0 double} {0×0 double} {[5]} {0×0 double} {0×0 double} {[ 3]} y = -5 19 1 9999 3 x = 1 2 3 4 5 y = -5 19 1 NaN 3 idx = 4 idx2 = 1 2 3 5 y = -5 19 1 2 3 y = -5 19 1 2 3