Cody

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

Solution 3428513

Submitted on 27 Oct 2020 by Harry Shrager
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 = [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')

B = 15 0 3

2   Pass
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')

B = 0

3   Pass
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')

B = []

4   Pass
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')

B = 0 0 0 0 0 8 0 25 2

5   Pass
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')

B(:,:,1) = 0.4947 0.7855 0.6223 0.3395 0.5040 0.9482 0.2088 0.0278 0.5427 0.3866 0.4074 0.2348 0.5701 0.8157 0.5154 0.3245 0.8182 0.5320 0.6359 0.8673 0.7376 0.5370 0.9918 0 0.4767 0.9473 0.8840 0.9396 0.2849 0.8668 0.4530 0.3407 0.0020 0.9412 0.4288 0.3139 0.1975 0.6536 0.5028 0.4129 0.8633 0.9530 0.7392 0.7853 0.4441 0.9720 0.9973 0.9434 0.6116 0.6774 0.2272 0.7235 0.8868 0.4077 0.8876 0.3043 0.6086 0.9843 0.6586 0.9128 0.4862 0.1243 0.7677 0.2865 0.5239 0.9801 0.4809 0.4179 0.4013 0.0762 0.2054 0.3456 0.0468 0.8650 0.7631 0.6357 0.4677 0.1729 0.1009 0.0717 0.6936 0.8568 0.5738 0.7453 0.4585 0.1393 0.5491 0.0108 0.4079 0.6359 0.4029 0.7506 0.1493 0.8026 0.5067 0.4312 0.0120 0.1178 0.6329 0.7790 B(:,:,2) = 0.3782 0 0.7394 0.8692 0.7150 0.9261 0.3487 0.6051 0.6361 0.9149 0.9288 0.8292 0.6837 0.3381 0.8861 0.9592 0.3883 0.2325 0.1294 0.2004 0.3707 0.8654 0.5505 0.3733 0.1826 0.1370 0.0710 0.2970 0.6866 0.4672 0.7749 0.6988 0.9287 0.9673 0.6010 0.2389 0.9972 0.0501 0.0277 0.8887 0.1334 0.1471 0.1477 0.6019 0.6018 0.0523 0.9476 0.3773 0.6213 0.4929 0.2471 0.8216 0.9288 0.6268 0.0765 0.7315 0.5045 0.1754 0.3905 0.5497 0.6933 0.7965 0.9837 0.9522 0.1316 0.3831 0.5347 0.4475 0.9525 0.9241 0.2491 0.8454 0.5126 0.0935 0.1162 0.2273 0.6479 0.0243 0.9360 0.8545 0.9848 0.1361 0.7998 0.0237 0.4133 0.8426 0.0649 0.8449 0.9904 0.6494 0.1193 0.8535 0.8541 0.9953 0.6561 0.3267 0.6271 0.2614 0.9121 0.0885 B(:,:,3) = 0.8171 0.2030 0.6134 0.1300 0.1038 0.6299 0.3130 0.7024 0.2888 0.9472 0.4086 0.5632 0.5691 0.4442 0.4342 0.1092 0.3893 0.4860 0.7324 0.6770 0.3316 0.1450 0.8665 0.1479 0.2207 0.2023 0.4360 0.5302 0.1151 0.5443 0.6846 0.0004 0.3148 0.8784 0.2647 0.4508 0.7868 0.1506 0.3521 0.0958 0.5605 0.3881 0.8807 0.3765 0.6699 0 0.1563 0.6565 0.4998 0.7145 0.5452 0.9806 0.5856 0.8532 0.9190 0.3637 0.6662 0.9713 0.6922 0.2679 0.2706 0.3517 0.3278 0.6474 0.4709 0.5988 0.1747 0.6873 0.3900 0.9891 0.1867 0.0237 0.4377 0.2794 0.9579 0.3259 0.7575 0.3320 0.3082 0.0975 0.6429 0.2106 0.2561 0.3961 0.5704 0.3952 0.3051 0.2701 0.8927 0.4946 0.7871 0.2720 0.7655 0.8416 0.4229 0.9319 0.4370 0.7316 0.3027 0.1985 B(:,:,4) = 0.8017 0.6963 0.8574 0.4231 0.7982 0.3435 0.6511 0.8025 0.3515 0.2538 0.2795 0.1352 0.3225 0.9838 0.4763 0.9827 0.1161 0.5348 0.3761 0.1250 0.5437 0.9694 0.7063 0.6898 0.3045 0.5041 0.7348 0.2169 0.4567 0.5992 0.2744 0.6961 0.0849 0.5181 0.6516 0.4241 0.0162 0.6520 0.1329 0.8762 0.9431 0.7216 0.5644 0.4687 0.1461 0.0229 0.4443 0.4809 0.2112 0.2372 0.7068 0.2117 0.0422 0.0879 0.0536 0.9835 0.6184 0.1957 0.4092 0.9676 0.8145 0.7558 0.9673 0.6283 0.2062 0.1060 0.6666 0.3551 0.5156 0.7629 0.2119 0.3993 0.8465 0.0582 0.9156 0.3588 0.2384 0.5214 0.8954 0.0316 0.0899 0.0693 0.7470 0.0811 0.6645 0.0296 0.2613 0.3029 0.9769 0.7251 0.3223 0.4007 0.9632 0.5625 0.4213 0.3868 0.1210 0.9680 0.9385 0.4844 B(:,:,5) = 0.2996 0.9206 0.1427 0.1827 0.0403 0.1205 0.7565 0.8437 0.1067 0.2651 0.8950 0.1837 0.9055 0.8855 0.6278 0.6198 0.3838 0.7898 0.5515 0.2010 0.0325 0.5384 0.3668 0.2667 0.7855 0.5986 0.5524 0.7440 0.4017 0.4714 0.7728 0.8203 0.0515 0.1350 0.0886 0.9433 0.4428 0.3684 0.4852 0.0300 0.0381 0.9683 0.5928 0.1949 0.2900 0.7031 0.4306 0.4164 0.3275 0.2011 0.7110 0.4608 0.0356 0.8364 0.2565 0.1011 0.3002 0.6115 0.8612 0.1110 0.8233 0.0617 0.0611 0.5098 0.9315 0.0962 0.9963 0.6508 0.3046 0.4369 0.5974 0.2796 0.0964 0.6742 0.8078 0.8137 0.3790 0.2028 0.4497 0.1780 0.4866 0.2581 0.1813 0.9240 0.0115 0.5418 0.2696 0.6190 0.8161 0.7894 0.6600 0.0232 0.0625 0.4736 0.5059 0.6010 0.3311 0.0722 0.1123 0.5325 B(:,:,6) = 0.8319 0.3404 0.1743 0.6477 0.7021 0.6826 0.4681 0.5139 0.5352 0.2874 0.6582 0.8470 0.4994 0.4308 0.9224 0.9155 0.3683 0.2225 0.9075 0.8099 0.0352 0.0299 0.4015 0.5657 0.0670 0.0820 0.7536 0.1516 0.4770 0.0085 0.2276 0.9236 0.7761 0.6253 0.8008 0.4246 0.9896 0.3913 0.7594 0.4936 0.3341 0.1455 0.1521 0.3768 0.1082 0.2502 0.9865 0.1400 0.6708 0.7709 0.1458 0.2557 0.3333 0.4834 0.1846 0.9537 0.0806 0.1038 0.0440 0.1323 0.9438 0.3791 0.7557 0.5495 0.9543 0.5031 0.6614 0.1966 0.2828 0.2068 0.7067 0.4334 0.9057 0.9035 0.5700 0.1233 0.3654 0.4531 0.9618 0.8837 0.4031 0.2679 0.8657 0.7851 0.0665 0.5476 0.9550 0.7931 0.7612 0.5964 0.6868 0.6646 0.5203 0.3802 0.8925 0.8788 0.4925 0.6375 0.9079 0.0778 B(:,:,7) = 0.5460 0.6692 0.5811 0.0709 0.2058 0.1251 0.6747 0.1658 0.8616 0.4374 0.9107 0.8464 0.4697 0.4987 0.2474 0.8065 0.7552 0.9983 0.6683 0.6006 0.3218 0.5318 0.2144 0.9143 0.3019 0.9938 0.3891 0.6925 0.1233 0.1698 0.0024 0.8818 0.9117 0.8322 0.4688 0.5198 0.5653 0.8840 0.3413 0.8054 0.2020 0.4767 0.6178 0.2275 0.1002 0.8314 0.0675 0.7276 0.0220 0.5255 0.2297 0.7441 0.2198 0.8770 0.1567 0.4017 0.6324 0.3849 0.9001 0.0354 0.5353 0.8743 0.9566 0.6005 0.2022 0.2617 0.9734 0.1850 0.5411 0.3318 0.4708 0.0266 0.0821 0.0463 0.7128 0.2878 0.5175 0.7825 0.2161 0.1103 0.7042 0.9413 0.4621 0.2681 0.8424 0.1769 0.6506 0.4457 0.7814 0.8511 0.4986 0.9303 0.0494 0.1009 0.3629 0.4696 0.5651 0.6603 0.3233 0.6435 B(:,:,8) = 0.3421 0.9202 0.8962 0.6964 0.6666 0.7670 0.9404 0.0491 0.9454 0.2166 0.9310 0.4260 0.1166 0.2355 0.7845 0.6227 0.8674 0.2315 0.4474 0.0013 0.0761 0.9909 0.5747 0.3225 0.2322 0.5513 0.7196 0.9239 0.0418 0.0313 0.8333 0.6599 0.1798 0.7323 0.3787 0.6228 0.9949 0.9183 0.9248 0.9821 0.7678 0.8425 0.8789 0.7130 0.9244 0.9347 0.2417 0.2758 0.7824 0.3090 0.7352 0.2667 0.4465 0.0808 0.7228 0.6524 0.9623 0.0459 0.2077 0.8736 0.4787 0.8501 0.5161 0.6007 0.3729 0.8840 0.8241 0.1609 0.9292 0.2706 0.1073 0.5464 0.4498 0.9821 0.4311 0.3783 0.5938 0.2038 0.0127 0.1652 0.4858 0.1525 0.8467 0.9675 0.9698 0.1491 0.2397 0.8042 0.5601 0.9133 0.5507 0.6927 0.1654 0.9109 0.5189 0.6215 0.3318 0.5191 0.4760 0.9334 B(:,:,9) = 0.5404 0.5461 0.4053 0.3681 0.9141 0.9956 0.2656 0.1698 0.5708 0.3532 0.1081 0.1061 0.1049 0.9853 0.2073 0.2432 0.7582 0.4118 0.3462 0.1602 0.8303 0.3955 0.9421 0.7822 0.2041 0.1730 0.9316 0.6750 0.0100 0.7452 0.8485 0.4483 0.7729 0.2895 0.3249 0.8489 0.2632 0.6458 0.1542 0.3791 0.6531 0.8513 0.2102 0.9177 0.3701 0.1431 0.3438 0.5432 0.5408 0.4784 0.6648 0.5920 0.5652 0.0701 0.7495 0.1739 0.6599 0.1833 0.5006 0.6543 0.8372 0.4169 0.5422 0.2683 0.6414 0.1359 0.3194 0.2397 0.5614 0.0391 0.7065 0.5939 0.2758 0.3302 0.2349 0.8149 0.9004 0.3887 0.5093 0.2984 0.0374 0.6270 0.8605 0.4489 0.3535 0.4112 0.6473 0.8025 0.6581 0.7145 0.2898 0.3149 0.4912 0.0882 0.9040 0.7230 0.1418 0.8561 0.7289 0.8240 B(:,:,10) = 0.3900 0.8971 0.8245 0.8711 0.9895 0.9269 0.8155 0.3824 0.6991 0.3954 0.8560 0.8890 0.8453 0.6351 0.6354 0.6879 0.0108 0.9775 0.9279 0.3382 0.6372 0.8054 0.3342 0.1654 0.8576 0.3077 0.7070 0.2363 0.4004 0.1321 0.9104 0.0933 0.1332 0.3313 0.7102 0.2380 0.3822 0.7412 0.7394 0.6321 0.0520 0.1411 0.7798 0.4689 0.1840 0.7497 0.7637 0.1247 0.9323 0.6871 0.1439 0.2786 0.0465 0.2522 0.5583 0.4514 0.6559 0.2670 0.2907 0.9996 0.8377 0.4350 0.2833 0.7542 0.2656 0.1028 0.4026 0.6291 0.2692 0.1984 0.9215 0.1740 0.6500 0.5745 0.0026 0.9118 ...

6   Pass
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')

B = 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 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 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 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 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 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 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 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 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 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 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 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 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 0 0 0 0 0 0 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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 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 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

7   Pass
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 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

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

B = 13.3000

Suggested Problems

More from this Author30

Community Treasure Hunt

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

Start Hunting!