Cody

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

Solution 1572369

Submitted on 1 Jul 2018 by Oliver Penn
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.5691 0.8516 0.8980 0.3599 0.8105 0.3763 0.0680 0.9650 0.7748 0.4483 0.3483 0.1623 0.7089 0.5993 0.0960 0.5689 0.0666 0.0081 0.6838 0.3596 0.9189 0.1661 0.6748 0 0.6666 0.4186 0.7374 0.8932 0.7305 0.9670 0.1397 0.5601 0.3674 0.1061 0.8902 0.7546 0.6825 0.5433 0.3840 0.9260 0.5649 0.3587 0.9615 0.1491 0.2724 0.7391 0.6792 0.7769 0.8787 0.0774 0.0355 0.4740 0.4087 0.0033 0.4025 0.9434 0.2307 0.2681 0.7587 0.2702 0.7180 0.8595 0.0913 0.0100 0.2402 0.7061 0.1608 0.3567 0.1933 0.7484 0.8049 0.4673 0.6111 0.9432 0.6885 0.2984 0.3630 0.6271 0.9875 0.4728 0.5265 0.3684 0.8461 0.8604 0.5512 0.2646 0.6390 0.7373 0.8917 0.4542 0.5520 0.2018 0.9842 0.1410 0.1793 0.4534 0.0689 0.5985 0.9399 0.9236 B(:,:,2) = 0.0824 0 0.9853 0.9915 0.3079 0.4853 0.3254 0.1118 0.7537 0.5554 0.2182 0.6822 0.6778 0.3141 0.9306 0.4226 0.7987 0.4423 0.7266 0.2921 0.7364 0.2509 0.0647 0.8425 0.0646 0.9635 0.0337 0.9049 0.7607 0.4307 0.0352 0.6535 0.7722 0.2653 0.9122 0.0793 0.9420 0.0541 0.5238 0.2587 0.0458 0.1483 0.5892 0.5640 0.9931 0.6790 0.4595 0.0698 0.2996 0.6370 0.5930 0.0417 0.2241 0.4321 0.4800 0.9078 0.0397 0.3267 0.1716 0.1987 0.5532 0.9942 0.3409 0.6550 0.2617 0.3253 0.3926 0.5729 0.2786 0.3402 0.5563 0.1268 0.5850 0.4636 0.5854 0.3399 0.6726 0.1335 0.7613 0.3234 0.2137 0.0288 0.2282 0.4395 0.4516 0.3953 0.4734 0.3607 0.0485 0.7467 0.9016 0.0798 0.6144 0.6868 0.4060 0.4187 0.7463 0.3022 0.9495 0.1936 B(:,:,3) = 0.7498 0.9729 0.2918 0.2495 0.9877 0.3306 0.1263 0.0406 0.6327 0.1051 0.9155 0.1135 0.4310 0.7054 0.3284 0.1658 0.2021 0.2467 0.7405 0.7636 0.4787 0.4629 0.1323 0.8674 0.3848 0.8064 0.6594 0.2004 0.9899 0.9528 0.0350 0.8612 0.6116 0.9444 0.2197 0.6885 0.6006 0.3821 0.2961 0.4612 0.4552 0.0573 0.5764 0.4840 0.3510 0 0.2431 0.5288 0.2023 0.8001 0.8418 0.0008 0.7976 0.4735 0.5078 0.6120 0.9526 0.1707 0.4627 0.2898 0.1396 0.9527 0.3222 0.1229 0.8399 0.4109 0.1487 0.9329 0.5745 0.9863 0.6883 0.3501 0.0873 0.8331 0.1142 0.8202 0.6628 0.1032 0.9251 0.1516 0.7068 0.8613 0.9091 0.4385 0.5479 0.9781 0.5166 0.2423 0.7437 0.2950 0.1310 0.8022 0.5181 0.3519 0.6597 0.5790 0.2319 0.8720 0.5582 0.4105 B(:,:,4) = 0.6787 0.4023 0.3428 0.4961 0.8958 0.6848 0.9805 0.9168 0.3030 0.0242 0.0569 0.9708 0.7105 0.9321 0.6398 0.3894 0.6768 0.2883 0.1518 0.2978 0.3119 0.7880 0.7876 0.9823 0.2632 0.4104 0.4781 0.2499 0.4954 0.7923 0.3565 0.0719 0.7587 0.4595 0.0436 0.2305 0.9599 0.5180 0.1164 0.0546 0.5386 0.0163 0.4659 0.2920 0.6458 0.9701 0.3229 0.2086 0.6071 0.9389 0.4200 0.2105 0.6668 0.4592 0.1465 0.3773 0.3983 0.4099 0.7819 0.5196 0.6496 0.4592 0.2546 0.8107 0.1093 0.4982 0.5359 0.7871 0.8852 0.9087 0.0581 0.3167 0.2222 0.1448 0.2217 0.3446 0.3565 0.9015 0.9051 0.4021 0.6513 0.9552 0.1317 0.2259 0.0208 0.8322 0.4643 0.8667 0.2846 0.1773 0.8875 0.4385 0.7552 0.9738 0.1917 0.8535 0.9108 0.4283 0.9182 0.2302 B(:,:,5) = 0.4232 0.6472 0.6895 0.4636 0.9686 0.6640 0.6721 0.9394 0.7871 0.3991 0.8445 0.3276 0.0996 0.9283 0.6009 0.9266 0.5320 0.5856 0.5282 0.2740 0.3997 0.6269 0.7478 0.6909 0.9117 0.2296 0.8736 0.0937 0.6946 0.3173 0.1304 0.0177 0.0023 0.4570 0.3186 0.8423 0.1739 0.6212 0.1187 0.3147 0.3090 0.7897 0.9950 0.4268 0.2221 0.8474 0.3329 0.8970 0.7277 0.5463 0.3895 0.7374 0.6605 0.8390 0.8821 0.6518 0.2815 0.2918 0.2004 0.4751 0.4635 0.2688 0.6856 0.0274 0.0960 0.0837 0.5123 0.8700 0.9447 0.5086 0.1341 0.0666 0.9058 0.1875 0.5126 0.2884 0.7243 0.3506 0.4594 0.5646 0.5550 0.8473 0.7127 0.3095 0.9170 0.0583 0.0716 0.9261 0.2659 0.6544 0.5542 0.8784 0.7834 0.8682 0.4921 0.0507 0.0923 0.0940 0.8616 0.7239 B(:,:,6) = 0.1173 0.5820 0.3714 0.3959 0.0767 0.4440 0.8269 0.4685 0.5602 0.7953 0.1239 0.6619 0.6473 0.3938 0.4267 0.9639 0.1205 0.2359 0.2186 0.5594 0.1111 0.9809 0.8487 0.9807 0.6175 0.6954 0.9995 0.8715 0.5857 0.2460 0.1259 0.7342 0.6412 0.5878 0.7084 0.0217 0.0047 0.1712 0.7175 0.6151 0.6966 0.0924 0.5117 0.8750 0.4660 0.0458 0.9782 0.1582 0.0720 0.0472 0.8138 0.7780 0.1842 0.2476 0.0757 0.4177 0.1996 0.5296 0.4499 0.9156 0.5821 0.6791 0.6646 0.2797 0.2467 0.1405 0.4689 0.9387 0.3306 0.2627 0.1117 0.5119 0.6906 0.4738 0.1070 0.4272 0.3550 0.8631 0.2667 0.8782 0.9744 0.2006 0.1518 0.7826 0.1583 0.4384 0.2285 0.9132 0.2528 0.9121 0.0147 0.7145 0.6757 0.3646 0.3570 0.3516 0.8128 0.5699 0.1611 0.6216 B(:,:,7) = 0.8638 0.0231 0.4907 0.2672 0.1183 0.1347 0.0710 0.6527 0.8166 0.3708 0.6760 0.9359 0.6779 0.0585 0.0122 0.6781 0.6232 0.2475 0.2783 0.2023 0.3014 0.8182 0.7771 0.1899 0.3868 0.8364 0.7345 0.7267 0.3228 0.1621 0.3651 0.4450 0.6626 0.5637 0.4181 0.3378 0.3587 0.3757 0.3481 0.7050 0.1924 0.2226 0.8849 0.6470 0.8206 0.9075 0.8656 0.8226 0.9010 0.1293 0.3935 0.5056 0.8592 0.0751 0.4237 0.9706 0.1487 0.2554 0.6015 0.3164 0.1093 0.2297 0.1915 0.5058 0.3226 0.2872 0.4607 0.4750 0.3964 0.5181 0.9150 0.0387 0.3272 0.9501 0.0037 0.6494 0.4089 0.5198 0.4773 0.3659 0.4104 0.1286 0.3824 0.6667 0.8629 0.2788 0.7713 0.5078 0.7380 0.8155 0.1987 0.0539 0.5710 0.4102 0.2630 0.3005 0.6276 0.6698 0.4970 0.4152 B(:,:,8) = 0.4119 0.8513 0.0766 0.4708 0.6226 0.3515 0.6634 0.7727 0.5212 0.5720 0.3788 0.7584 0.7064 0.7550 0.9045 0.3030 0.7971 0.3083 0.4063 0.0787 0.1853 0.0506 0.6233 0.7705 0.0379 0.3408 0.9025 0.7420 0.7853 0.9790 0.7134 0.5196 0.2447 0.1552 0.6423 0.6678 0.1626 0.9813 0.8387 0.8787 0.3182 0.9593 0.1573 0.7388 0.2300 0.3666 0.5315 0.4969 0.4725 0.8556 0.2060 0.2902 0.6618 0.8971 0.0451 0.8889 0.6960 0.0379 0.5164 0.2449 0.6857 0.7863 0.5389 0.2214 0.4460 0.7628 0.4117 0.4477 0.4474 0.3799 0.3537 0.3081 0.6628 0.0348 0.7919 0.2693 0.9136 0.4032 0.1331 0.2328 0.6553 0.1558 0.8951 0.4269 0.4291 0.2260 0.6026 0.5712 0.3706 0.3702 0.4558 0.8365 0.7622 0.9575 0.8581 0.9483 0.9590 0.3455 0.1300 0.3603 B(:,:,9) = 0.9893 0.3445 0.3272 0.4224 0.3080 0.3267 0.5162 0.3998 0.3280 0.7123 0.1289 0.3393 0.3682 0.4505 0.4834 0.6237 0.7016 0.8576 0.7344 0.7130 0.3367 0.6695 0.8160 0.9659 0.8018 0.9635 0.7238 0.3453 0.1998 0.5128 0.7526 0.4425 0.3082 0.0514 0.8459 0.6047 0.9242 0.5669 0.4276 0.8277 0.2393 0.1319 0.3867 0.3118 0.1029 0.5209 0.0110 0.7894 0.6748 0.2009 0.2247 0.0070 0.4555 0.6537 0.8910 0.5418 0.4669 0.7773 0.7779 0.3228 0.3779 0.0531 0.2724 0.2625 0.1425 0.4559 0.1988 0.5895 0.4845 0.5683 0.8886 0.8448 0.9703 0.6369 0.9299 0.2675 0.3241 0.6941 0.5737 0.7098 0.4097 0.8731 0.6921 0.7451 0.4392 0.6691 0.4103 0.0080 0.3547 0.3133 0.8904 0.6970 0.2342 0.2027 0.6381 0.5706 0.5975 0.9048 0.3545 0.8395 B(:,:,10) = 0.5466 0.3134 0.0852 0.2745 0.4751 0.7948 0.8040 0.1955 0.0007 0.1479 0.0966 0.1231 0.1331 0.7535 0.6510 0.6185 0.3684 0.5505 0.1757 0.9293 0.9818 0.1141 0.7631 0.0051 0.4386 0.7533 0.2593 0.5502 0.3320 0.8973 0.9771 0.2325 0.9782 0.7260 0.2941 0.4175 0.8540 0.9113 0.9972 0.5561 0.2337 0.2396 0.2911 0.4144 0.4893 0.6869 0.1320 0.8192 0.3577 0.7098 0.5246 0.4421 0.9006 0.0038 0.1606 0.2902 0.6133 0.4840 0.7965 0.3642 0.2215 0.7773 0.2867 0.7126 0.3582 0.0549 0.3841 0.7066 0.1547 0.1182 0.5136 0.1483 0.7381 0.2077 0.3597 0.0159 ...

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!