Cody

# Problem 2661. Change Vector Value

Solution 1625863

Submitted on 12 Sep 2018 by Michael Cappello
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
d=[1 2 2 2 1 2 1 2]; vector=[1 2 3 4 5 6 7 8]; new_vec=[1 4 6 8 9 12 13 16]; assert(isequal(change_direction(vector,d),new_vec)) filetext = fileread('change_direction.m') assert(isempty(strfind(filetext, 'if')))

v = 1 4 6 8 5 12 7 16 v = 1 4 6 8 9 12 13 16 filetext = 'function v= change_direction(v,dir) v(dir==2) = v(dir==2) * 2 v(dir==1) = v(dir==1) * 2-1 end %This code written by profile_id 34524 '

2   Pass
d=[ones(1,5) 2*ones(1,4) ones(1,3)]; vector=1:length(d); new_vec=[1 3 5 7 9 12 14 16 18 19 21 23]; assert(isequal(change_direction(vector,d),new_vec)) filetext = fileread('change_direction.m') assert(isempty(strfind(filetext, 'if')))

v = 1 2 3 4 5 12 14 16 18 10 11 12 v = 1 3 5 7 9 12 14 16 18 19 21 23 filetext = 'function v= change_direction(v,dir) v(dir==2) = v(dir==2) * 2 v(dir==1) = v(dir==1) * 2-1 end %This code written by profile_id 34524 '

3   Pass
d=ones(1,6); vector=[1 2 3 4 5 6]; new_vec=2*vector-1; assert(isequal(change_direction(vector,d),new_vec)) filetext = fileread('change_direction.m') assert(isempty(strfind(filetext, 'if')))

v = 1 2 3 4 5 6 v = 1 3 5 7 9 11 filetext = 'function v= change_direction(v,dir) v(dir==2) = v(dir==2) * 2 v(dir==1) = v(dir==1) * 2-1 end %This code written by profile_id 34524 '

4   Pass
d=ones(1,50); vector=zeros(1,50); new_vec=vector-1; assert(isequal(change_direction(vector,d),new_vec)) filetext = fileread('change_direction.m') assert(isempty(strfind(filetext, 'if')))

v = Columns 1 through 29 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 30 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 v = Columns 1 through 29 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 Columns 30 through 50 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 filetext = 'function v= change_direction(v,dir) v(dir==2) = v(dir==2) * 2 v(dir==1) = v(dir==1) * 2-1 end %This code written by profile_id 34524 '

### Community Treasure Hunt

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

Start Hunting!