Cody

Problem 3108. Don't Try, give up and return NaN.

Solution 601923

Submitted on 25 Mar 2015 by rifat
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
A = 1:5; N = [-1 2 6]; values = [NaN 2 NaN]; assert(isequaln(giveup(A,N),values))

2   Pass
%% A = 10:-2:2; N = 5:-1:1; y_correct = 2:2:10; assert(isequaln(giveup(A,N),y_correct))

3   Pass
%% A = [1 2 3 4 10]; N = 5; y_correct = 10; assert(isequaln(giveup(A,N),y_correct))

4   Pass
%% A = 10:-2:2; N = -1; y_correct = NaN; assert(isequaln(giveup(A,N),y_correct))

5   Pass
%% A = [4 5 6]; N = [6 2]; y_correct = [NaN 5]; assert(isequaln(giveup(A,N),y_correct))

6   Pass
%% A = 4:randi([20 30]) ; N = randi(length(A)+20,1,10); K = N+3 ; K(K>max(A)) = NaN; y_correct = K; assert(isequaln(giveup(A,N),y_correct))

7   Pass
%% A = [-23 4 56 0 44 11]; N = [7:-1.5:-2]; y_correct = [NaN NaN 0 NaN -23 NaN NaN]; assert(isequaln(giveup(A,N),y_correct))

8   Pass
%% A = magic(3); N = magic(4); y_correct = [ NaN 3 4 NaN 5 NaN NaN 7 2 6 9 NaN 1 NaN NaN 8]; assert(isequaln(giveup(A,N),y_correct))

9   Pass
%% A = magic(3); N = magic(4)-1; y_correct = [ NaN 8 3 NaN 1 NaN 2 6 7 9 5 NaN 4 NaN NaN NaN]; assert(isequaln(giveup(A,N),y_correct))

10   Pass
%% A = magic(4); N = magic(3)-1; y_correct = [ 7 NaN 2 5 4 11 9 14 16]; assert(isequaln(giveup(A,N),y_correct))

Suggested Problems

More from this Author41

Community Treasure Hunt

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

Start Hunting!