Cody

# Problem 824. Set the array elements whose value is 13 to 0

Solution 3022654

Submitted on 1 Oct 2020 at 19:39
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   Fail
A = [15 13 3]; y_correct = [15 0 3]; assert(isequal(your_fcn_name(A),y_correct)) filetext = fileread('your_fcn_name.m'); assert(isempty(strfind(filetext, 'for')),'for command is forbidden') assert(isempty(strfind(filetext, 'while')),'while command is forbidden') assert(isempty(strfind(filetext, 'find')),'find command is forbidden') assert(isempty(strfind(filetext, 'ind2sub')),'ind2sub command is forbidden')

n = 3

Unrecognized function or variable 'k'. Error in your_fcn_name (line 4) [y,i]= (A(k)==13) Error in Test1 (line 3) assert(isequal(your_fcn_name(A),y_correct))

2   Fail
A = 13; y_correct = 0; assert(isequal(your_fcn_name(A),y_correct)) filetext = fileread('your_fcn_name.m'); assert(isempty(strfind(filetext, 'for')),'for command is forbidden') assert(isempty(strfind(filetext, 'while')),'while command is forbidden') assert(isempty(strfind(filetext, 'find')),'find command is forbidden') assert(isempty(strfind(filetext, 'ind2sub')),'ind2sub command is forbidden')

n = 1

Unrecognized function or variable 'k'. Error in your_fcn_name (line 4) [y,i]= (A(k)==13) Error in Test2 (line 3) assert(isequal(your_fcn_name(A),y_correct))

3   Fail
A = []; y_correct = []; assert(isequal(your_fcn_name(A),y_correct)) filetext = fileread('your_fcn_name.m'); assert(isempty(strfind(filetext, 'for')),'for command is forbidden') assert(isempty(strfind(filetext, 'while')),'while command is forbidden') assert(isempty(strfind(filetext, 'find')),'find command is forbidden') assert(isempty(strfind(filetext, 'ind2sub')),'ind2sub command is forbidden')

n = 0

Unrecognized function or variable 'k'. Error in your_fcn_name (line 4) [y,i]= (A(k)==13) Error in Test3 (line 3) assert(isequal(your_fcn_name(A),y_correct))

4   Fail
A = [13 0 13; 13 13 8; 13 25 2]; titi = [0 0 0 ; 0 0 8;0 25 2]; assert(isequal(your_fcn_name(A),titi)) filetext = fileread('your_fcn_name.m'); assert(isempty(strfind(filetext, 'for')),'for command is forbidden') assert(isempty(strfind(filetext, 'while')),'while command is forbidden') assert(isempty(strfind(filetext, 'find')),'find command is forbidden') assert(isempty(strfind(filetext, 'ind2sub')),'ind2sub command is forbidden')

n = 9

Unrecognized function or variable 'k'. Error in your_fcn_name (line 4) [y,i]= (A(k)==13) Error in Test4 (line 4) assert(isequal(your_fcn_name(A),titi))

5   Fail
A=rand(10,10,10); A(1,2,2)=13; A(3,4,1)=13; A(5,6,3)=13; % what you cannot do but me I can ;) ! titi = A; I=find(titi==13); [u,v,w]=ind2sub(size(titi),I); for ii = 1 : numel(u) titi(u(ii),v(ii),w(ii))=0; end assert(isequal(your_fcn_name(A),titi)) filetext = fileread('your_fcn_name.m'); assert(isempty(strfind(filetext, 'for')),'for command is forbidden') assert(isempty(strfind(filetext, 'while')),'while command is forbidden') assert(isempty(strfind(filetext, 'find')),'find command is forbidden') assert(isempty(strfind(filetext, 'ind2sub')),'ind2sub command is forbidden')

n = 1000

Unrecognized function or variable 'k'. Error in your_fcn_name (line 4) [y,i]= (A(k)==13) Error in Test5 (line 13) assert(isequal(your_fcn_name(A),titi))

6   Fail
A = repmat(13,89,17); assert(isequal(your_fcn_name(A),repmat(0,89,17))) filetext = fileread('your_fcn_name.m'); assert(isempty(strfind(filetext, 'for')),'for command is forbidden') assert(isempty(strfind(filetext, 'while')),'while command is forbidden') assert(isempty(strfind(filetext, 'find')),'find command is forbidden') assert(isempty(strfind(filetext, 'ind2sub')),'ind2sub command is forbidden')

n = 1513

Unrecognized function or variable 'k'. Error in your_fcn_name (line 4) [y,i]= (A(k)==13) Error in Test6 (line 2) assert(isequal(your_fcn_name(A),repmat(0,89,17)))

7   Fail
A= magic(5); B =A; B(3,3) = 0 assert(isequal(your_fcn_name(A),B)) filetext = fileread('your_fcn_name.m'); assert(isempty(strfind(filetext, 'for')),'for command is forbidden') assert(isempty(strfind(filetext, 'while')),'while command is forbidden') assert(isempty(strfind(filetext, 'find')),'find command is forbidden') assert(isempty(strfind(filetext, 'ind2sub')),'ind2sub command is forbidden')

B = 17 24 1 8 15 23 5 7 14 16 4 6 0 20 22 10 12 19 21 3 11 18 25 2 9 n = 25

Unrecognized function or variable 'k'. Error in your_fcn_name (line 4) [y,i]= (A(k)==13) Error in Test7 (line 4) assert(isequal(your_fcn_name(A),B))

8   Fail
A= 13.3; B = A; assert(isequal(your_fcn_name(A),B))

n = 1

Unrecognized function or variable 'k'. Error in your_fcn_name (line 4) [y,i]= (A(k)==13) Error in Test8 (line 3) assert(isequal(your_fcn_name(A),B))

### Community Treasure Hunt

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

Start Hunting!