Cody

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

Solution 2015428

Submitted on 12 Nov 2019 by Brendan Coetzer
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 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')

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

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

A = 0 0 0 0 0 8 0 25 2 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')

A(:,:,1) = 0.3182 0.6336 0.6043 0.4425 0.2489 0.3213 0.2672 0.0553 0.8805 0.2098 0.1274 0.6842 0.2754 0.8731 0.4288 0.5542 0.3516 0.1472 0.5658 0.4249 0.2531 0.8184 0.1919 0 0.4786 0.7953 0.0653 0.0356 0.6187 0.2987 0.2987 0.8201 0.3716 0.1039 0.0452 0.2881 0.7284 0.4470 0.4750 0.2112 0.4743 0.2638 0.5257 0.1288 0.4105 0.8150 0.3651 0.9434 0.9969 0.7327 0.2859 0.9963 0.2138 0.3020 0.6026 0.0567 0.6017 0.2445 0.3541 0.2129 0.7265 0.8472 0.1350 0.2614 0.7487 0.7109 0.7453 0.3778 0.8635 0.4011 0.9515 0.0968 0.3799 0.4304 0.6843 0.5008 0.5487 0.4138 0.1584 0.0120 0.5984 0.8842 0.0151 0.8795 0.9380 0.1781 0.1146 0.8612 0.0011 0.0416 0.2728 0.3898 0.3222 0.7844 0.3822 0.2674 0.1832 0.2776 0.0456 0.9167 A(:,:,2) = 0.1495 0 0.5027 0.2015 0.3103 0.1644 0.4826 0.1106 0.0574 0.8183 0.7732 0.6341 0.3352 0.9993 0.3604 0.4613 0.5454 0.9548 0.8628 0.7328 0.5323 0.3837 0.6662 0.2766 0.2625 0.4941 0.8773 0.0940 0.1598 0.7443 0.9772 0.9204 0.8955 0.1617 0.6751 0.4478 0.3776 0.3078 0.1273 0.9537 0.9695 0.6818 0.8434 0.9702 0.2478 0.7240 0.6864 0.0242 0.5265 0.6748 0.8206 0.9477 0.0425 0.6476 0.8861 0.9148 0.1545 0.3718 0.7058 0.5808 0.0810 0.2248 0.9684 0.1397 0.4645 0.1221 0.5855 0.6469 0.0827 0.2457 0.6397 0.8968 0.3204 0.3350 0.8074 0.6098 0.0463 0.6513 0.9057 0.2459 0.7771 0.8527 0.6715 0.1734 0.0797 0.0263 0.8250 0.4090 0.0557 0.9692 0.2398 0.2919 0.7890 0.8768 0.4013 0.3779 0.4605 0.0274 0.7482 0.4324 A(:,:,3) = 0.1258 0.4151 0.4387 0.3422 0.0790 0.3019 0.7791 0.4467 0.4607 0.6057 0.4850 0.6078 0.1402 0.6835 0.5212 0.5429 0.7356 0.6697 0.2533 0.8935 0.8023 0.1375 0.8835 0.3150 0.7027 0.4359 0.7011 0.1038 0.8905 0.3493 0.1438 0.5017 0.5613 0.1359 0.0162 0.1468 0.0760 0.4512 0.2498 0.8422 0.4821 0.2866 0.5025 0.9017 0.4161 0 0.5855 0.0525 0.6705 0.0721 0.4634 0.8110 0.7411 0.0578 0.5064 0.9165 0.4058 0.2751 0.7262 0.0768 0.1364 0.6475 0.6165 0.1279 0.7909 0.3685 0.3118 0.3487 0.1988 0.8889 0.6572 0.5446 0.6705 0.5808 0.4088 0.7068 0.9125 0.1195 0.7803 0.6115 0.4918 0.0793 0.5908 0.8224 0.2354 0.4559 0.1284 0.5132 0.9835 0.0665 0.9748 0.4593 0.7016 0.7761 0.7405 0.8204 0.9799 0.3085 0.7116 0.2600 A(:,:,4) = 0.4684 0.7597 0.7118 0.5243 0.5460 0.7542 0.1305 0.9896 0.6521 0.4093 0.5680 0.3115 0.4836 0.3788 0.3650 0.0604 0.2345 0.5124 0.6953 0.8668 0.1308 0.1177 0.4486 0.8343 0.0063 0.3922 0.9205 0.4213 0.8336 0.0269 0.7265 0.3175 0.7071 0.6452 0.9178 0.1630 0.8976 0.1292 0.2574 0.5496 0.0853 0.5566 0.0182 0.5362 0.5413 0.6627 0.2284 0.2004 0.7823 0.0891 0.7797 0.8054 0.4652 0.0787 0.1715 0.2395 0.8613 0.7611 0.0241 0.5571 0.9186 0.8991 0.4948 0.8144 0.5829 0.4309 0.6743 0.5843 0.8701 0.8623 0.8125 0.1699 0.6254 0.5351 0.2737 0.0404 0.6488 0.7744 0.0231 0.5834 0.1056 0.4891 0.5997 0.0856 0.7716 0.1410 0.4238 0.2877 0.2728 0.5047 0.4356 0.3482 0.0389 0.8013 0.9338 0.3164 0.8435 0.5191 0.8546 0.7772 A(:,:,5) = 0.7302 0.8930 0.4126 0.5632 0.4262 0.3534 0.7519 0.7585 0.5959 0.7912 0.8673 0.0469 0.7181 0.8134 0.0906 0.0610 0.0514 0.9086 0.9743 0.3965 0.8242 0.2065 0.5055 0.5752 0.1515 0.0985 0.8873 0.5158 0.6548 0.6310 0.0838 0.4030 0.6591 0.3096 0.8270 0.4435 0.1784 0.1226 0.8304 0.6010 0.7412 0.7590 0.3983 0.7776 0.3914 0.6424 0.1546 0.5367 0.3597 0.9146 0.6808 0.6378 0.0355 0.4511 0.3147 0.2939 0.3535 0.0988 0.8759 0.4865 0.1723 0.4009 0.9983 0.6710 0.1167 0.4380 0.5781 0.4907 0.1881 0.4399 0.4744 0.5510 0.7897 0.3981 0.5538 0.8776 0.6706 0.7349 0.3719 0.7374 0.8455 0.0061 0.6268 0.6944 0.3849 0.8061 0.4179 0.9889 0.2785 0.2000 0.3643 0.3343 0.9024 0.0965 0.1394 0.5046 0.8073 0.4054 0.3574 0.6633 A(:,:,6) = 0.4741 0.1787 0.1401 0.8976 0.9114 0.4339 0.5093 0.8353 0.8863 0.8209 0.4961 0.2626 0.4907 0.8563 0.1366 0.1364 0.9336 0.6613 0.6188 0.3527 0.6528 0.8019 0.9411 0.1978 0.2513 0.3976 0.1124 0.8135 0.0510 0.9696 0.5693 0.2125 0.4131 0.6713 0.2760 0.6617 0.7475 0.6689 0.7088 0.6103 0.4711 0.0927 0.2658 0.5339 0.3316 0.7613 0.4095 0.0136 0.1866 0.1657 0.0200 0.9006 0.7687 0.9585 0.9869 0.0047 0.3364 0.7303 0.4911 0.5611 0.9979 0.1413 0.7781 0.1726 0.6744 0.0105 0.2357 0.4942 0.9299 0.3239 0.3693 0.6941 0.9576 0.5123 0.5213 0.7614 0.8987 0.6338 0.3100 0.6916 0.6417 0.5797 0.5149 0.9369 0.6547 0.6306 0.3066 0.9801 0.3947 0.5682 0.7495 0.6870 0.4372 0.3882 0.4274 0.6090 0.1378 0.0770 0.8775 0.5270 A(:,:,7) = 0.8554 0.8286 0.0136 0.6728 0.3020 0.8129 0.0891 0.8031 0.7190 0.1050 0.4239 0.7801 0.9229 0.0404 0.2328 0.1109 0.6072 0.7893 0.0147 0.9801 0.4273 0.3706 0.8726 0.7878 0.9609 0.8302 0.9031 0.5322 0.1762 0.9336 0.5375 0.2852 0.0715 0.2208 0.7655 0.9608 0.6314 0.0339 0.5139 0.5208 0.3856 0.6858 0.0842 0.0450 0.4294 0.8769 0.0043 0.6696 0.9419 0.8937 0.6624 0.5036 0.0061 0.5918 0.6876 0.4960 0.6736 0.0275 0.0695 0.6663 0.6312 0.7631 0.9181 0.1676 0.3420 0.2210 0.3264 0.0168 0.4010 0.0738 0.7197 0.7049 0.5965 0.2394 0.3439 0.7797 0.6813 0.5798 0.8082 0.6838 0.0525 0.2910 0.1918 0.1507 0.1950 0.7900 0.3237 0.6830 0.9637 0.0243 0.6527 0.3467 0.7515 0.3290 0.5382 0.2712 0.4952 0.4038 0.6086 0.7083 A(:,:,8) = 0.4125 0.9789 0.4086 0.1196 0.1794 0.3536 0.0526 0.2749 0.9565 0.0579 0.0465 0.5143 0.7433 0.3940 0.5017 0.6745 0.6366 0.7544 0.1214 0.3709 0.4609 0.9787 0.0359 0.7630 0.8840 0.9086 0.0022 0.7783 0.7459 0.9828 0.6871 0.1273 0.2018 0.3172 0.2461 0.9087 0.7662 0.5999 0.8381 0.2952 0.8187 0.2035 0.7000 0.5801 0.0756 0.8023 0.0261 0.6717 0.2903 0.5968 0.6023 0.1029 0.2127 0.1149 0.6804 0.9043 0.5163 0.1580 0.1711 0.1265 0.3231 0.2818 0.0472 0.3158 0.1316 0.1447 0.6939 0.7909 0.5551 0.5473 0.9978 0.7289 0.1063 0.2740 0.4442 0.7689 0.5491 0.7044 0.8230 0.8453 0.4079 0.5567 0.8221 0.8558 0.0340 0.3044 0.7517 0.6976 0.3364 0.9544 0.0796 0.8974 0.5352 0.9989 0.4009 0.1179 0.2972 0.0085 0.5436 0.8507 A(:,:,9) = 0.7632 0.1615 0.8162 0.9742 0.2631 0.7051 0.6643 0.7241 0.9911 0.0932 0.0851 0.2286 0.6403 0.5975 0.0605 0.8524 0.5598 0.6585 0.8156 0.3800 0.2488 0.7093 0.4600 0.9986 0.0332 0.4561 0.7366 0.9458 0.0713 0.6741 0.0693 0.1107 0.8837 0.9246 0.9459 0.6404 0.0721 0.3237 0.4450 0.3473 0.0603 0.7952 0.1263 0.6841 0.7028 0.1603 0.6255 0.6867 0.8636 0.3027 0.4334 0.1697 0.7966 0.3004 0.9011 0.3546 0.2284 0.5519 0.0857 0.8763 0.8825 0.4146 0.9180 0.9201 0.5883 0.6866 0.0242 0.6950 0.0885 0.3996 0.2236 0.0722 0.4638 0.7591 0.7768 0.1971 0.2771 0.1218 0.9934 0.2516 0.0734 0.4244 0.3234 0.8979 0.4262 0.7831 0.4949 0.9173 0.0486 0.4890 0.8899 0.2394 0.3583 0.8860 0.0115 0.5551 0.2524 0.8360 0.7703 0.1702 A(:,:,10) = 0.0987 0.3640 0.2842 0.9487 0.6014 0.8693 0.0302 0.4182 0.6650 0.2204 0.1883 0.8139 0.4350 0.2837 0.1920 0.7182 0.8725 0.2727 0.3244 0.8737 0.7544 0.9924 0.8425 0.4861 0.6703 0.7688 0.8933 0.9751 0.0512 0.3563 0.6861 0.2781 0.9512 0.8202 0.6057 0.6294 0.7369 0.5195 0.3069 0.2989 0.5171 0.4101 0.3196 0.0045 0.7811 0.4074 0.2139 0.4214 0.1358 0.6785 0.1453 0.7214 0.1549 0.1677 0.6397 0.9744 0.8952 0.2035 0.2565 0.7428 0.4040 0.2857 0.4130 0.4804 0.3942 0.6190 0.4810 0.0646 0.0808 0.8896 0.7797 0.2552 0.0547 0.4655 0.0580 0.1014 ...

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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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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 ...

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

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