Cody

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

Solution 3707288

Submitted on 18 Nov 2020 by Danuanping
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')

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

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

A = []

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

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

A(:,:,1) = 0.0528 0.1403 0.5877 0.1958 0.2432 0.5510 0.3302 0.2984 0.1878 0.6015 0.1646 0.9717 0.8767 0.5339 0.9478 0.8278 0.0197 0.4466 0.8240 0.3802 0.0602 0.4095 0.2771 0 0.1969 0.6722 0.2163 0.3105 0.3343 0.9714 0.2887 0.6587 0.6430 0.1514 0.3092 0.9948 0.6950 0.2362 0.4407 0.2329 0.2789 0.6400 0.0264 0.4089 0.0754 0.5106 0.2271 0.2630 0.1907 0.2821 0.1880 0.6070 0.1498 0.2017 0.5466 0.5946 0.2758 0.4784 0.0593 0.4155 0.2404 0.8489 0.7876 0.2567 0.6663 0.4435 0.0278 0.7372 0.0309 0.4788 0.8208 0.6143 0.6788 0.4766 0.7846 0.8927 0.7881 0.2608 0.4009 0.8705 0.1027 0.4310 0.8787 0.6341 0.9878 0.9570 0.4347 0.5574 0.3628 0.1703 0.7200 0.8898 0.4139 0.2601 0.6037 0.0629 0.0378 0.2870 0.5025 0.2795 A(:,:,2) = 0.0076 0 0.4991 0.6811 0.7510 0.8340 0.7606 0.7850 0.1195 0.2876 0.4027 0.6389 0.3934 0.4120 0.3890 0.3840 0.4660 0.9955 0.7627 0.7652 0.6216 0.9189 0.6202 0.8797 0.9672 0.1697 0.1795 0.7134 0.1577 0.6446 0.1006 0.9598 0.1218 0.8740 0.5169 0.1701 0.7592 0.5690 0.8459 0.3947 0.8783 0.5936 0.7005 0.2612 0.0299 0.5485 0.5694 0.6314 0.8171 0.5621 0.6575 0.2943 0.5344 0.4710 0.5459 0.3901 0.7215 0.2621 0.9474 0.7879 0.8750 0.0284 0.7525 0.8920 0.3486 0.8312 0.8536 0.8374 0.0807 0.0756 0.4970 0.0594 0.1291 0.8131 0.4761 0.0688 0.5246 0.7428 0.6088 0.5918 0.1414 0.3591 0.7933 0.5520 0.5410 0.1990 0.2451 0.2155 0.4343 0.8804 0.1449 0.0381 0.7880 0.9465 0.8792 0.0991 0.7312 0.9507 0.6850 0.2613 A(:,:,3) = 0.9947 0.6075 0.0148 0.3625 0.3711 0.0267 0.1415 0.2317 0.7468 0.1326 0.0193 0.4216 0.2970 0.2975 0.0942 0.1715 0.1607 0.9807 0.2748 0.1155 0.2215 0.0788 0.5265 0.0463 0.1504 0.4651 0.8431 0.0958 0.3826 0.4636 0.2048 0.1461 0.5162 0.5437 0.3451 0.0616 0.6469 0.7781 0.3764 0.0273 0.1878 0.7791 0.0546 0.5992 0.0473 0 0.3461 0.8116 0.4986 0.0566 0.9982 0.6239 0.4178 0.9904 0.6434 0.9041 0.8303 0.4211 0.0880 0.4353 0.5031 0.1979 0.5798 0.9644 0.2130 0.8700 0.1663 0.0133 0.4975 0.0837 0.7617 0.6735 0.0589 0.9452 0.0766 0.4366 0.0995 0.5101 0.7098 0.6853 0.3820 0.2304 0.5232 0.3064 0.8106 0.6277 0.4430 0.8817 0.2878 0.7869 0.7427 0.8337 0.1216 0.1294 0.4485 0.9835 0.6693 0.4305 0.8551 0.3333 A(:,:,4) = 0.4955 0.7099 0.3260 0.2398 0.2644 0.7555 0.1378 0.6689 0.7255 0.4393 0.2766 0.5516 0.9037 0.2691 0.4124 0.4509 0.9180 0.8099 0.9396 0.4566 0.3576 0.8097 0.6985 0.1546 0.6585 0.7013 0.2915 0.8916 0.4299 0.0055 0.4034 0.4414 0.0729 0.5849 0.9887 0.7267 0.5100 0.3526 0.1992 0.3902 0.3098 0.0322 0.6496 0.4795 0.7643 0.1862 0.3705 0.3864 0.0822 0.0028 0.7764 0.9907 0.7524 0.8746 0.0000 0.2213 0.9194 0.4947 0.9655 0.6731 0.6618 0.9839 0.0354 0.4636 0.0700 0.2486 0.7082 0.0312 0.5525 0.4623 0.5829 0.5635 0.0685 0.4792 0.5558 0.4431 0.1331 0.6232 0.7084 0.4163 0.9739 0.1606 0.5300 0.9038 0.2564 0.8668 0.9119 0.5852 0.2046 0.1109 0.1180 0.4293 0.7450 0.3988 0.7241 0.0559 0.3416 0.3351 0.6194 0.7955 A(:,:,5) = 0.1751 0.7183 0.8710 0.8836 0.0166 0.8847 0.8404 0.5919 0.4799 0.6739 0.6608 0.9437 0.5033 0.9667 0.0670 0.4135 0.2582 0.7188 0.1497 0.7369 0.6612 0.5432 0.9880 0.5732 0.7523 0.5797 0.8878 0.6954 0.3844 0.6943 0.2779 0.5794 0.7735 0.1601 0.8054 0.4073 0.9745 0.5411 0.5758 0.6941 0.3232 0.2181 0.6404 0.8205 0.7698 0.1985 0.9517 0.9345 0.2318 0.7220 0.7045 0.4198 0.7599 0.2010 0.5097 0.1561 0.2989 0.3086 0.8809 0.9452 0.2068 0.4132 0.8178 0.1333 0.5427 0.7750 0.4344 0.7079 0.6047 0.1314 0.5139 0.2435 0.2071 0.4709 0.2403 0.5979 0.1696 0.6197 0.9008 0.1749 0.0150 0.4694 0.2803 0.8408 0.0268 0.5979 0.8798 0.2459 0.4853 0.9754 0.7224 0.6926 0.2375 0.6926 0.8780 0.9058 0.5449 0.3677 0.0491 0.9922 A(:,:,6) = 0.4993 0.0911 0.7745 0.7376 0.4541 0.7733 0.8634 0.1173 0.4427 0.7731 0.8500 0.6805 0.6207 0.3063 0.3403 0.0467 0.1867 0.9592 0.2338 0.7369 0.5189 0.9826 0.1779 0.0417 0.8559 0.9788 0.1451 0.7983 0.3428 0.2052 0.3788 0.2145 0.0996 0.5223 0.5195 0.6872 0.1228 0.6640 0.3443 0.1765 0.7214 0.1578 0.5535 0.7938 0.7918 0.6037 0.5576 0.2602 0.5632 0.9503 0.8510 0.2803 0.6176 0.0454 0.8885 0.0882 0.0424 0.3252 0.1457 0.9918 0.1267 0.2697 0.9505 0.8694 0.0270 0.0037 0.8563 0.4052 0.6975 0.9626 0.1377 0.0376 0.8365 0.0170 0.6617 0.1493 0.2076 0.8887 0.3300 0.5342 0.3614 0.0931 0.8955 0.4711 0.4298 0.8691 0.6229 0.8474 0.7788 0.0065 0.6297 0.4543 0.2716 0.5428 0.6535 0.4106 0.6079 0.1368 0.1401 0.9766 A(:,:,7) = 0.5984 0.2151 0.7306 0.0399 0.5155 0.5592 0.4826 0.2305 0.1722 0.7430 0.8373 0.6270 0.9734 0.3492 0.2294 0.5428 0.8958 0.8479 0.5882 0.1125 0.4409 0.6573 0.9578 0.2053 0.3033 0.0697 0.0518 0.0062 0.8411 0.8794 0.8410 0.3012 0.0222 0.3224 0.0271 0.1809 0.6324 0.9274 0.4044 0.0404 0.0406 0.4163 0.2915 0.9995 0.3925 0.4199 0.3131 0.3117 0.8305 0.4020 0.1144 0.7721 0.0644 0.3361 0.8731 0.1877 0.2632 0.9135 0.7621 0.4304 0.6433 0.8507 0.1292 0.3887 0.1166 0.7071 0.1649 0.1085 0.2234 0.7550 0.3607 0.6367 0.4563 0.7166 0.3622 0.3355 0.9766 0.5848 0.2872 0.3674 0.5982 0.2113 0.2998 0.6307 0.5521 0.1412 0.1665 0.8384 0.2271 0.3660 0.6371 0.0559 0.1592 0.6835 0.5259 0.5327 0.4120 0.0806 0.9168 0.5532 A(:,:,8) = 0.9447 0.9712 0.7643 0.6687 0.9445 0.9688 0.5654 0.8110 0.3391 0.3898 0.0153 0.6068 0.8197 0.0399 0.9688 0.4495 0.9576 0.3248 0.0845 0.3740 0.8516 0.2830 0.5903 0.4061 0.8069 0.1373 0.3257 0.7571 0.1928 0.7482 0.3765 0.7955 0.3729 0.6004 0.0789 0.8883 0.5422 0.6048 0.2634 0.5530 0.5948 0.6805 0.8776 0.9868 0.9313 0.9333 0.6128 0.8351 0.4483 0.7471 0.9174 0.7138 0.5705 0.6989 0.4215 0.2915 0.2024 0.4670 0.4823 0.1135 0.8134 0.5400 0.3571 0.0974 0.0462 0.4155 0.1165 0.6326 0.7387 0.8783 0.9982 0.8994 0.0716 0.1109 0.4289 0.3899 0.5379 0.8048 0.4802 0.6953 0.5018 0.6147 0.0072 0.4629 0.2946 0.3051 0.2302 0.2796 0.1880 0.2229 0.7135 0.0002 0.6833 0.8881 0.1838 0.1567 0.8534 0.7797 0.0457 0.1329 A(:,:,9) = 0.9438 0.9472 0.1586 0.1230 0.4146 0.9559 0.6866 0.3512 0.4078 0.6516 0.5599 0.2616 0.4457 0.1910 0.1885 0.5613 0.5857 0.0987 0.3891 0.5435 0.7103 0.1067 0.8914 0.8194 0.2190 0.0838 0.3871 0.5624 0.6321 0.2169 0.0972 0.8709 0.2356 0.9809 0.7801 0.5053 0.4582 0.1714 0.7576 0.7679 0.0981 0.6424 0.6371 0.7753 0.5733 0.2480 0.5267 0.9983 0.1557 0.2411 0.8744 0.9353 0.1338 0.7567 0.7005 0.5517 0.7794 0.6647 0.7294 0.6944 0.0748 0.9640 0.2769 0.8504 0.6009 0.4385 0.9810 0.9404 0.6441 0.6184 0.2597 0.2890 0.8174 0.2544 0.5954 0.4100 0.2932 0.5870 0.6991 0.7329 0.9283 0.4003 0.0520 0.3419 0.2463 0.0641 0.9568 0.2921 0.3984 0.3583 0.6860 0.0071 0.7329 0.0472 0.9317 0.7930 0.0895 0.7187 0.2100 0.2315 A(:,:,10) = 0.2369 0.9127 0.9786 0.1839 0.8247 0.2610 0.8294 0.2341 0.8538 0.1047 0.7524 0.1031 0.6533 0.6028 0.4492 0.0527 0.9765 0.8652 0.3000 0.7773 0.4313 0.6774 0.5582 0.9902 0.9346 0.8701 0.1081 0.4804 0.0842 0.4162 0.8675 0.8486 0.7065 0.4232 0.8195 0.1441 0.9248 0.3535 0.4114 0.4433 0.8630 0.6628 0.2915 0.3203 0.1998 0.4924 0.0207 0.1043 0.7991 0.8258 0.7302 0.8351 0.7009 0.5362 0.8220 0.8989 0.6046 0.1554 0.7363 0.5691 0.1846 0.0075 0.4464 0.3054 0.5192 0.4698 0.4527 0.2352 0.5560 0.2275 0.9768 0.2459 0.9718 0.8547 0.0460 0.8158 ...

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

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

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 A = 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))

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