Cody

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

Solution 2981713

Submitted on 23 Sep 2020
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   Fail
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 13 3

Assertion failed.

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

B = []

4   Fail
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 = 13 0 13 13 13 8 13 25 2

Assertion failed.

5   Fail
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.3747 0.2422 0.5304 0.6498 0.6204 0.8271 0.6058 0.7255 0.0206 0.3432 0.2774 0.9853 0.7822 0.6269 0.2285 0.9128 0.6575 0.1150 0.6277 0.4713 0.1032 0.8860 0.1082 13.0000 0.7952 0.9805 0.4519 0.5917 0.3123 0.9350 0.5084 0.7635 0.2137 0.7438 0.6129 0.2117 0.5310 0.2138 0.4530 0.2863 0.7838 0.0883 0.7889 0.1420 0.6560 0.9260 0.5481 0.3429 0.3012 0.9962 0.3247 0.8376 0.3025 0.0515 0.2194 0.4636 0.6324 0.5873 0.5430 0.4983 0.1831 0.0228 0.2036 0.7774 0.9291 0.3248 0.8735 0.1356 0.8610 0.4128 0.1079 0.9401 0.7855 0.5807 0.6953 0.5610 0.6613 0.8021 0.6579 0.0546 0.4409 0.3450 0.6900 0.0456 0.9047 0.4835 0.8949 0.0626 0.7025 0.6443 0.5940 0.8877 0.8411 0.4344 0.7812 0.7391 0.2864 0.8494 0.9140 0.5396 B(:,:,2) = 0.3763 13.0000 0.2765 0.3004 0.0320 0.3038 0.4794 0.6123 0.6314 0.8676 0.5931 0.9474 0.6797 0.0099 0.4554 0.1479 0.0533 0.5434 0.7279 0.8670 0.4391 0.2147 0.5658 0.7859 0.9510 0.9765 0.4170 0.2266 0.7952 0.3040 0.6566 0.0715 0.5754 0.5164 0.4535 0.4028 0.0639 0.4738 0.3424 0.5676 0.7529 0.6669 0.0892 0.8482 0.8815 0.2954 0.4368 0.8479 0.0998 0.1701 0.8643 0.3207 0.8096 0.2217 0.4396 0.3909 0.1014 0.9736 0.9162 0.9785 0.2615 0.5827 0.5203 0.2476 0.2159 0.2386 0.0524 0.0694 0.9221 0.0931 0.6567 0.5571 0.7519 0.7696 0.2280 0.9784 0.6921 0.9527 0.5098 0.8860 0.7660 0.2014 0.2749 0.7753 0.0141 0.9487 0.9070 0.0987 0.2247 0.2823 0.0888 0.1484 0.4211 0.7450 0.8447 0.6513 0.3961 0.8313 0.9552 0.1906 B(:,:,3) = 0.6013 0.7180 0.0584 0.9201 0.3656 0.5299 0.1799 0.0248 0.6803 0.1948 0.2052 0.0632 0.9875 0.7972 0.7378 0.9818 0.9293 0.7443 0.3075 0.5750 0.9369 0.3065 0.4038 0.8364 0.6397 0.0040 0.7458 0.8020 0.3412 0.5065 0.6039 0.5959 0.3116 0.3524 0.2962 0.7232 0.2463 0.1405 0.4632 0.5664 0.3520 0.3546 0.4976 0.0489 0.1635 13.0000 0.2330 0.0633 0.1133 0.7447 0.3733 0.4361 0.6491 0.4196 0.1321 0.9652 0.5470 0.5878 0.1246 0.9134 0.6124 0.6054 0.8785 0.5321 0.7956 0.1293 0.9327 0.3518 0.7461 0.1133 0.1620 0.7517 0.2948 0.9984 0.8717 0.9593 0.7087 0.8279 0.5500 0.2152 0.9352 0.6102 0.6881 0.3846 0.4620 0.6297 0.7335 0.9948 0.6214 0.6926 0.0005 0.0285 0.5321 0.6848 0.2538 0.2649 0.5380 0.6184 0.5789 0.2966 B(:,:,4) = 0.9954 0.8595 0.1750 0.6276 0.1470 0.9694 0.5487 0.9303 0.6824 0.0489 0.0398 0.1236 0.7229 0.8808 0.7645 0.8182 0.1747 0.4741 0.2344 0.5519 0.5076 0.8195 0.1393 0.5376 0.4963 0.5738 0.7832 0.6125 0.5659 0.4457 0.7242 0.2310 0.8610 0.7108 0.4045 0.6461 0.9749 0.6278 0.9115 0.8771 0.0060 0.1650 0.4464 0.8535 0.1004 0.6713 0.1372 0.2499 0.4431 0.0576 0.9646 0.5715 0.7293 0.2440 0.8694 0.2623 0.7121 0.2771 0.6094 0.7757 0.3526 0.1019 0.4905 0.8923 0.2869 0.3195 0.2138 0.7326 0.3339 0.6960 0.3984 0.3001 0.7091 0.1990 0.8351 0.9474 0.8877 0.4446 0.8419 0.2724 0.7531 0.9589 0.8462 0.7559 0.1299 0.7560 0.5138 0.9089 0.3409 0.4933 0.1944 0.8709 0.3113 0.5087 0.4960 0.7185 0.5900 0.5779 0.6007 0.4687 B(:,:,5) = 0.4314 0.9452 0.8617 0.2734 0.4195 0.8852 0.9884 0.6585 0.0423 0.8324 0.1261 0.7937 0.7711 0.6027 0.1826 0.5448 0.4650 0.9682 0.0249 0.0340 0.3507 0.1138 0.2292 0.6316 0.0033 0.4791 0.6503 0.5724 0.8538 0.1054 0.0994 0.4208 0.7177 0.4387 0.5881 0.2619 0.2419 0.1268 0.5913 0.4383 0.9851 0.0924 0.5286 0.4208 0.8083 0.5782 0.7467 0.9066 0.2535 0.8298 0.7642 0.2035 0.1859 0.6869 0.3016 0.0872 0.5880 0.3277 0.3058 0.1700 0.2014 0.4259 0.4619 0.7547 0.4600 0.7838 0.9038 0.2529 0.6803 0.5057 0.4598 0.0093 0.7985 0.0641 0.2712 0.0054 0.5141 0.2375 0.5311 0.0474 0.0159 0.7950 0.9796 0.3901 0.6573 0.9384 0.5576 0.2479 0.1113 0.5698 0.0593 0.6150 0.8916 0.7387 0.8662 0.5019 0.2337 0.5293 0.1334 0.8445 B(:,:,6) = 0.1738 0.1830 0.5063 0.8564 0.6735 0.0777 0.1225 0.1233 0.5730 0.0905 0.4486 0.9041 0.6725 0.6480 0.7006 0.3409 0.7033 0.7270 0.9931 0.3546 0.0519 0.5148 0.4004 0.6429 0.7871 0.1091 0.3376 0.2662 0.3920 0.9226 0.2286 0.6255 0.1003 0.8209 0.0776 0.5010 0.7092 0.0578 0.1789 0.9648 0.7865 0.8268 0.7545 0.9970 0.5014 0.0421 0.7692 0.8953 0.4250 0.6339 0.1714 0.3345 0.4276 0.9858 0.8341 0.8928 0.1317 0.0603 0.5066 0.2739 0.3765 0.9098 0.6614 0.6252 0.9095 0.1422 0.1746 0.7969 0.6449 0.9013 0.8032 0.8194 0.0281 0.6560 0.5375 0.5209 0.4344 0.0149 0.1015 0.0715 0.9908 0.7097 0.7858 0.8413 0.7612 0.3024 0.6693 0.6773 0.3356 0.8357 0.2302 0.1912 0.2310 0.0669 0.4253 0.1721 0.2206 0.1342 0.4383 0.5106 B(:,:,7) = 0.1802 0.4933 0.0733 0.8380 0.6012 0.3606 0.9789 0.4373 0.3818 0.3873 0.6093 0.1577 0.7545 0.0154 0.0520 0.5073 0.7642 0.6127 0.6111 0.3641 0.1445 0.9323 0.8347 0.6352 0.7082 0.3882 0.5949 0.0089 0.2783 0.5469 0.2122 0.3088 0.1579 0.9366 0.3881 0.1350 0.9666 0.2401 0.8736 0.0105 0.6541 0.0209 0.0887 0.1215 0.3287 0.4059 0.3226 0.2212 0.9809 0.8379 0.5082 0.3661 0.9694 0.0376 0.8058 0.2904 0.6783 0.7197 0.7686 0.2284 0.5882 0.5738 0.9036 0.4747 0.8093 0.7366 0.9754 0.4004 0.9385 0.4583 0.7819 0.3898 0.4061 0.2443 0.5886 0.8391 0.7327 0.2681 0.9042 0.8252 0.8396 0.5150 0.8509 0.6937 0.6267 0.6213 0.3265 0.2035 0.5805 0.1518 0.2426 0.0069 0.7347 0.0666 0.8200 0.6322 0.3480 0.1990 0.2724 0.9992 B(:,:,8) = 0.1337 0.2669 0.7011 0.0162 0.1772 0.3163 0.6567 0.4305 0.8386 0.7507 0.6118 0.8536 0.3521 0.8420 0.2795 0.2575 0.6272 0.7838 0.1936 0.4384 0.9460 0.6534 0.2508 0.3294 0.2700 0.5208 0.5363 0.1717 0.0153 0.7953 0.8121 0.2486 0.9000 0.4877 0.1632 0.2715 0.6185 0.5138 0.9177 0.2657 0.4424 0.9464 0.2715 0.6823 0.1995 0.7182 0.3505 0.7182 0.4856 0.3991 0.4222 0.9550 0.3281 0.5537 0.1505 0.8722 0.0478 0.7363 0.4716 0.3911 0.2574 0.9375 0.1499 0.2962 0.2177 0.5939 0.8810 0.1658 0.1489 0.5291 0.0278 0.7081 0.7175 0.9230 0.0318 0.8446 0.7150 0.9754 0.1594 0.4385 0.7882 0.6773 0.5322 0.0969 0.5908 0.9737 0.1447 0.4728 0.3971 0.8392 0.0515 0.9947 0.9618 0.2971 0.8145 0.7608 0.7009 0.6926 0.9858 0.1020 B(:,:,9) = 0.0569 0.8157 0.3583 0.3845 0.1816 0.8983 0.4228 0.4338 0.1221 0.5389 0.3014 0.2475 0.6290 0.2736 0.2063 0.5599 0.1894 0.9156 0.1489 0.1260 0.6007 0.6900 0.8491 0.0363 0.9950 0.1568 0.3778 0.6297 0.6897 0.4786 0.7160 0.3406 0.7558 0.2785 0.6367 0.4246 0.4309 0.1538 0.3994 0.3618 0.1534 0.3947 0.2152 0.4578 0.4372 0.6913 0.4138 0.9545 0.9868 0.4264 0.4476 0.3611 0.9571 0.5164 0.0845 0.5360 0.0045 0.7319 0.2830 0.3407 0.0701 0.2689 0.2843 0.5083 0.1902 0.7769 0.1305 0.2632 0.1345 0.7418 0.1821 0.1084 0.0998 0.4987 0.1837 0.3036 0.9766 0.9868 0.5737 0.0258 0.3767 0.1900 0.3179 0.1872 0.7395 0.8882 0.3158 0.5231 0.0098 0.2880 0.0783 0.3394 0.6412 0.8498 0.1641 0.7969 0.8238 0.8101 0.1663 0.3273 B(:,:,10) = 0.8839 0.9389 0.3875 0.5550 0.0983 0.5048 0.6551 0.9332 0.8721 0.2361 0.7884 0.4592 0.2832 0.9784 0.2504 0.0361 0.2007 0.3699 0.1380 0.8816 0.0763 0.8467 0.9099 0.6494 0.5888 0.7995 0.1606 0.3092 0.2816 0.3637 0.0795 0.9377 0.4440 0.3090 0.7862 0.3868 0.8960 0.9340 0.7153 0.4713 0.0207 0.9224 0.3921 0.7574 0.3654 0.2088 0.5437 0.4331 0.4269 0.1362 0.3154 0.4902 0.5616 0.8270 0.3042 0.9637 0.8234 0.3191 0.2330 0.0744 0.2662 0.0779 0.1736 0.1208 0.9427 0.2039 0.8970 0.7117 0.8659 0.1019 0.7993 0.8600 0.0537 0.2220 0.8607 0.5826 ...

Assertion failed.

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

Assertion failed.

7   Fail
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 13 20 22 10 12 19 21 3 11 18 25 2 9

Assertion failed.

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

B = 13.3000

### Community Treasure Hunt

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

Start Hunting!