Cody

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

Solution 3633658

Submitted on 12 Nov 2020 by Jan Olsen
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')

ans = 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')

ans = 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')

ans = []

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

ans = 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')

ans(:,:,1) = 0.0200 0.9468 0.9492 0.1069 0.5577 0.9452 0.7181 0.1447 0.1173 0.9872 0.6292 0.7137 0.5239 0.4889 0.7248 0.6057 0.8134 0.0852 0.2310 0.5276 0.7400 0.2016 0.6586 0 0.6919 0.4184 0.8429 0.4304 0.2407 0.0441 0.2303 0.1569 0.9119 0.2457 0.5808 0.0598 0.9849 0.3599 0.3200 0.2753 0.3581 0.2484 0.0373 0.8062 0.8504 0.3845 0.9830 0.3283 0.4787 0.4282 0.1320 0.4004 0.7375 0.4689 0.9945 0.7029 0.6854 0.3482 0.9893 0.4468 0.9592 0.2752 0.3771 0.7407 0.5684 0.8766 0.0351 0.0135 0.0658 0.5834 0.3679 0.5419 0.5845 0.8846 0.3679 0.3360 0.6201 0.2069 0.0874 0.3875 0.3682 0.4206 0.8606 0.2735 0.2892 0.2031 0.7725 0.0882 0.5762 0.6413 0.5240 0.8636 0.4807 0.7392 0.0789 0.9410 0.1008 0.4687 0.8936 0.9224 ans(:,:,2) = 0.0531 0 0.6403 0.0784 0.3079 0.4818 0.5780 0.2304 0.6247 0.9244 0.4238 0.2781 0.0760 0.7501 0.2408 0.1663 0.0915 0.8393 0.2441 0.7310 0.2043 0.8195 0.0640 0.9508 0.8308 0.1045 0.7140 0.5014 0.9021 0.0113 0.1098 0.7040 0.4189 0.2751 0.5664 0.4614 0.5329 0.8191 0.5879 0.4993 0.6949 0.4073 0.3139 0.9609 0.6020 0.0369 0.8654 0.8784 0.0192 0.3535 0.3362 0.0854 0.0667 0.0495 0.0423 0.3423 0.5863 0.6410 0.4804 0.8914 0.5178 0.1622 0.5693 0.8619 0.4336 0.9494 0.6236 0.3203 0.0471 0.9458 0.5506 0.7145 0.9344 0.4949 0.5365 0.8922 0.0892 0.0147 0.0207 0.6778 0.4657 0.6770 0.5487 0.9344 0.4210 0.3400 0.3533 0.6593 0.4686 0.1272 0.9788 0.3207 0.3394 0.6619 0.2131 0.8914 0.3056 0.2292 0.7594 0.1070 ans(:,:,3) = 0.0166 0.8604 0.6549 0.3445 0.6393 0.2385 0.4700 0.6832 0.1022 0.9315 0.4080 0.1011 0.7223 0.2457 0.3533 0.7477 0.3259 0.0271 0.1888 0.9223 0.3729 0.9407 0.0887 0.5086 0.5375 0.4609 0.0200 0.8932 0.0810 0.1200 0.2302 0.7967 0.0504 0.7218 0.3314 0.8249 0.8571 0.9399 0.1949 0.6915 0.2186 0.5022 0.1907 0.9134 0.5575 0 0.5307 0.1702 0.8817 0.3619 0.3588 0.7612 0.3036 0.0098 0.6478 0.7992 0.2535 0.0892 0.9043 0.0601 0.7308 0.0850 0.4891 0.0183 0.6692 0.6546 0.3133 0.2017 0.2667 0.1580 0.6681 0.4189 0.3644 0.0949 0.7911 0.4781 0.3558 0.5162 0.4963 0.8279 0.5343 0.7187 0.4214 0.0040 0.5770 0.7569 0.7009 0.7697 0.5632 0.4314 0.0493 0.8321 0.0069 0.9901 0.2029 0.6793 0.6849 0.6823 0.8593 0.4496 ans(:,:,4) = 0.1448 0.8744 0.4344 0.4266 0.5827 0.5479 0.5488 0.9718 0.3801 0.9692 0.6052 0.1233 0.8043 0.1889 0.1938 0.9055 0.1243 0.2125 0.3009 0.0160 0.7393 0.4040 0.1350 0.6152 0.3116 0.0987 0.1946 0.6803 0.6052 0.8548 0.4043 0.0321 0.5649 0.4426 0.3751 0.2954 0.4531 0.1259 0.4981 0.1159 0.0402 0.6251 0.6799 0.8862 0.7851 0.3453 0.3171 0.6749 0.6808 0.6150 0.2723 0.0996 0.5452 0.8747 0.3349 0.6565 0.3918 0.0480 0.7379 0.8824 0.4865 0.2299 0.4196 0.0272 0.0055 0.3531 0.3348 0.2807 0.8302 0.8086 0.4034 0.6813 0.5202 0.8441 0.3559 0.1128 0.4708 0.8651 0.2897 0.7426 0.0096 0.4442 0.6035 0.9526 0.4774 0.3197 0.5643 0.2597 0.2178 0.6114 0.8077 0.5696 0.2048 0.9070 0.1825 0.8866 0.9502 0.1341 0.0959 0.5323 ans(:,:,5) = 0.1812 0.4145 0.2655 0.2602 0.4711 0.1228 0.5021 0.6666 0.5235 0.2172 0.9062 0.3223 0.0085 0.9663 0.4037 0.2850 0.4514 0.8839 0.7126 0.4483 0.1112 0.0209 0.1855 0.2449 0.8791 0.2121 0.3122 0.6270 0.9434 0.7697 0.5257 0.7252 0.1732 0.6165 0.4686 0.7931 0.2264 0.7950 0.4966 0.2310 0.4656 0.3180 0.9700 0.9332 0.4230 0.1483 0.8811 0.8309 0.7999 0.5472 0.2169 0.9298 0.7839 0.5494 0.6738 0.0151 0.6150 0.0142 0.5733 0.6217 0.3137 0.4209 0.0662 0.2732 0.3903 0.9664 0.4052 0.3538 0.7476 0.9725 0.3056 0.4244 0.5636 0.6665 0.6985 0.6547 0.6175 0.5768 0.2236 0.0989 0.8745 0.7560 0.8450 0.2602 0.2291 0.4082 0.0805 0.8136 0.2796 0.3166 0.3643 0.7416 0.3305 0.1412 0.3669 0.0120 0.5055 0.5599 0.1760 0.2283 ans(:,:,6) = 0.3189 0.8717 0.6700 0.5694 0.4687 0.5902 0.8364 0.7412 0.2166 0.7413 0.3731 0.1518 0.9668 0.0485 0.9887 0.5893 0.3254 0.1293 0.5506 0.9004 0.3223 0.0149 0.3040 0.0230 0.0150 0.6445 0.5079 0.4575 0.5270 0.0305 0.1703 0.7599 0.8601 0.3271 0.2076 0.6349 0.3269 0.4770 0.2796 0.4515 0.3041 0.9043 0.0314 0.9308 0.3765 0.2199 0.1459 0.8069 0.1747 0.1698 0.7263 0.3655 0.1065 0.2145 0.9792 0.5170 0.0013 0.1270 0.9840 0.1529 0.1053 0.6246 0.8681 0.8701 0.2549 0.5059 0.8751 0.3204 0.4572 0.3687 0.5763 0.0283 0.9046 0.5733 0.8133 0.4947 0.6810 0.0121 0.1882 0.7179 0.3424 0.0711 0.6014 0.7840 0.7748 0.7896 0.8227 0.7156 0.9587 0.5981 0.4965 0.8521 0.3472 0.9648 0.2864 0.9572 0.2396 0.0342 0.0692 0.4079 ans(:,:,7) = 0.6314 0.7848 0.4958 0.0649 0.4239 0.3516 0.0292 0.6569 0.3212 0.1722 0.5250 0.8701 0.2641 0.2189 0.2935 0.8217 0.4032 0.6607 0.6345 0.4112 0.3529 0.9237 0.9940 0.5011 0.9367 0.1614 0.7653 0.0216 0.9325 0.5581 0.8584 0.5619 0.7073 0.1360 0.5380 0.2781 0.1327 0.9167 0.7743 0.6499 0.1333 0.0994 0.3250 0.6661 0.9205 0.9667 0.6030 0.7782 0.9443 0.1814 0.9344 0.7424 0.4621 0.4555 0.5019 0.3590 0.3395 0.0885 0.3264 0.4343 0.0364 0.0045 0.3607 0.1577 0.1047 0.8094 0.4325 0.9924 0.2775 0.7440 0.8786 0.7532 0.8212 0.4938 0.3202 0.4510 0.6591 0.0794 0.9021 0.3862 0.4624 0.1680 0.2220 0.8688 0.9088 0.9066 0.2013 0.0931 0.9661 0.7317 0.8670 0.2105 0.7655 0.0392 0.0343 0.7796 0.3956 0.1560 0.7266 0.9809 ans(:,:,8) = 0.4075 0.5498 0.8694 0.3514 0.5533 0.2980 0.6534 0.9595 0.0495 0.5152 0.2301 0.7814 0.8978 0.4013 0.6766 0.7473 0.1885 0.2360 0.9394 0.4008 0.5736 0.7576 0.2879 0.5275 0.1369 0.4422 0.5794 0.2273 0.2038 0.4850 0.4006 0.3786 0.1387 0.0682 0.3105 0.3947 0.3874 0.4987 0.7362 0.8403 0.8532 0.6615 0.2177 0.1680 0.1282 0.8727 0.7722 0.2441 0.1687 0.0217 0.8599 0.3053 0.7267 0.7106 0.5957 0.6492 0.8050 0.7758 0.1659 0.8173 0.0025 0.4174 0.5335 0.2365 0.1486 0.7089 0.5416 0.3469 0.0763 0.1650 0.9962 0.3346 0.4609 0.1742 0.5505 0.5581 0.3923 0.2035 0.5125 0.7181 0.2248 0.7915 0.6416 0.3407 0.2524 0.1774 0.8680 0.5723 0.4368 0.8506 0.4492 0.6689 0.3104 0.0696 0.0305 0.5202 0.7837 0.2135 0.7790 0.2517 ans(:,:,9) = 0.3223 0.1716 0.3844 0.0076 0.8493 0.7166 0.3019 0.8776 0.4843 0.4972 0.9202 0.0342 0.9836 0.5052 0.7564 0.1781 0.2204 0.2467 0.0442 0.4933 0.6882 0.6699 0.8287 0.5001 0.9017 0.5383 0.9344 0.3341 0.8120 0.5465 0.2284 0.0445 0.8241 0.7342 0.2292 0.6770 0.4026 0.2760 0.1473 0.6423 0.8705 0.8787 0.6671 0.6821 0.8489 0.1383 0.8994 0.2200 0.0338 0.0010 0.5374 0.4484 0.3632 0.7567 0.8099 0.2343 0.1793 0.5188 0.3176 0.3624 0.0253 0.6209 0.7121 0.1466 0.2827 0.6249 0.6288 0.8024 0.8092 0.3426 0.4219 0.0554 0.2772 0.6150 0.1572 0.0940 0.5209 0.9315 0.9362 0.4424 0.2669 0.7716 0.9974 0.7549 0.1051 0.3422 0.6305 0.7543 0.1598 0.0681 0.3184 0.8412 0.4594 0.1664 0.1872 0.1079 0.0758 0.6631 0.9755 0.9595 ans(:,:,10) = 0.5784 0.7165 0.6978 0.3082 0.4263 0.1630 0.4652 0.0935 0.4755 0.7301 0.6148 0.1632 0.9293 0.1521 0.7867 0.9903 0.3706 0.7290 0.2620 0.4967 0.4619 0.6026 0.6588 0.6157 0.1316 0.7899 0.5648 0.1475 0.7400 0.1287 0.1283 0.1013 0.7208 0.0569 0.9686 0.4580 0.5873 0.2134 0.3472 0.6256 0.7798 0.2376 0.5485 0.6831 0.9813 0.7229 0.3717 0.1718 0.0717 0.2343 0.3768 0.7998 0.6278 0.7110 0.9606 0.5441 0.9639 0.1179 0.3811 0.4141 0.8848 0.1869 0.9443 0.6737 0.3115 0.4477 0.9291 0.6407 0.4840 0.3850 0.1553 0.3171 0.8445 0.0251 ...

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

ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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 ans = 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))

ans = 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!