Cody

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

Solution 855388

Submitted on 23 Mar 2016 by David Schafer
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.0142 0.9909 0.1315 0.3897 0.5316 0.9037 0.6309 0.7674 0.2359 0.4319 0.1189 0.6143 0.9414 0.8845 0.9399 0.3489 0.3067 0.6013 0.2618 0.5830 0.5079 0.9070 0.5171 0 0.7204 0.2417 0.3861 0.6896 0.9133 0.2874 0.8197 0.7132 0.4386 0.3203 0.9271 0.5198 0.9123 0.5688 0.8249 0.9147 0.3488 0.6649 0.4789 0.7473 0.2147 0.6398 0.0103 0.2465 0.2399 0.3171 0.2538 0.4761 0.6811 0.6687 0.9781 0.3533 0.3107 0.8614 0.6052 0.7933 0.2000 0.4203 0.5337 0.7659 0.9735 0.5458 0.0716 0.4728 0.3183 0.4083 0.0132 0.5992 0.2801 0.9476 0.7737 0.3093 0.4121 0.0344 0.9903 0.0898 0.5082 0.2345 0.5759 0.1875 0.2522 0.9770 0.0311 0.1009 0.7625 0.3833 0.2154 0.9563 0.6478 0.5258 0.1914 0.7091 0.4627 0.6115 0.9022 0.0755 B(:,:,2) = 0.1752 0 0.0074 0.5837 0.1527 0.7123 0.7456 0.9471 0.8812 0.6220 0.8819 0.4129 0.8056 0.1990 0.4794 0.1812 0.0951 0.9638 0.6911 0.0606 0.7193 0.8144 0.9554 0.9752 0.0258 0.4347 0.5568 0.4073 0.9584 0.2486 0.0377 0.8835 0.5493 0.3810 0.6651 0.9317 0.0180 0.6016 0.3107 0.2250 0.3383 0.2526 0.1354 0.0374 0.0018 0.7510 0.5143 0.0119 0.5017 0.5682 0.5349 0.2523 0.3197 0.8000 0.9683 0.0800 0.2977 0.8218 0.9204 0.7070 0.0840 0.4562 0.8788 0.3820 0.6239 0.3455 0.3461 0.1056 0.0923 0.7652 0.6148 0.4292 0.3592 0.2008 0.5923 0.1964 0.5048 0.4119 0.7761 0.4553 0.3198 0.0342 0.5867 0.0376 0.4055 0.3664 0.0013 0.0715 0.5680 0.2440 0.9021 0.1464 0.8850 0.8457 0.1402 0.0953 0.4409 0.6328 0.4290 0.1436 B(:,:,3) = 0.7204 0.8391 0.9234 0.6957 0.4478 0.5164 0.0853 0.3893 0.7146 0.2097 0.3431 0.2384 0.0050 0.0989 0.3231 0.5716 0.1833 0.5036 0.3515 0.5434 0.6735 0.7039 0.2091 0.2513 0.6119 0.4967 0.1347 0.5533 0.8493 0.0422 0.6579 0.8364 0.6082 0.5362 0.0274 0.1132 0.8271 0.0694 0.4681 0.2508 0.7261 0.6570 0.1948 0.9558 0.2210 0 0.4071 0.5928 0.1569 0.4789 0.6060 0.9881 0.6217 0.7784 0.9847 0.1951 0.2188 0.9568 0.8268 0.2031 0.5301 0.0426 0.7027 0.6915 0.8204 0.8962 0.2920 0.7091 0.4914 0.6440 0.9209 0.5535 0.6242 0.6117 0.0003 0.0775 0.8298 0.9366 0.4504 0.1125 0.1596 0.8789 0.0716 0.4457 0.9474 0.3030 0.8181 0.7756 0.4244 0.4798 0.1650 0.2934 0.5147 0.3484 0.0639 0.1388 0.2594 0.1881 0.6745 0.2395 B(:,:,4) = 0.1336 0.2652 0.4399 0.8447 0.9434 0.5889 0.8529 0.1248 0.7177 0.0650 0.1967 0.1859 0.6538 0.2883 0.3816 0.6494 0.2370 0.1853 0.2514 0.0685 0.1749 0.5136 0.8814 0.0654 0.8178 0.8122 0.5971 0.5060 0.9824 0.1628 0.5434 0.8108 0.0700 0.9514 0.7804 0.9676 0.4532 0.7543 0.3344 0.9803 0.8842 0.9964 0.1909 0.6814 0.5173 0.9864 0.1691 0.4727 0.2953 0.6873 0.8480 0.2916 0.5520 0.3792 0.4490 0.5727 0.9896 0.8860 0.1621 0.0913 0.0392 0.6516 0.3994 0.1238 0.3584 0.3660 0.8754 0.4920 0.4367 0.9523 0.2273 0.1299 0.8423 0.8816 0.5345 0.0562 0.4629 0.6876 0.8864 0.9111 0.9164 0.1546 0.7492 0.9163 0.6139 0.7240 0.8253 0.7830 0.9302 0.9417 0.9765 0.9352 0.7150 0.8286 0.0444 0.3157 0.3154 0.5224 0.7991 0.4767 B(:,:,5) = 0.2812 0.3937 0.1691 0.8854 0.9273 0.6692 0.1365 0.9963 0.6659 0.9282 0.8997 0.9935 0.8029 0.5806 0.7764 0.2921 0.6148 0.4901 0.7248 0.2727 0.0576 0.2157 0.7504 0.4852 0.3739 0.1976 0.8044 0.7864 0.1150 0.8566 0.5121 0.1820 0.1598 0.8824 0.8891 0.2345 0.4168 0.0408 0.3063 0.7546 0.1706 0.8937 0.1711 0.7614 0.5946 0.1807 0.6575 0.8393 0.0370 0.5986 0.6919 0.9408 0.4047 0.5431 0.9728 0.9239 0.7651 0.1945 0.9715 0.0749 0.6300 0.4088 0.4811 0.9677 0.9515 0.2694 0.3697 0.5803 0.2420 0.1926 0.2150 0.1902 0.5105 0.4158 0.3910 0.3201 0.9569 0.9900 0.1427 0.2129 0.6163 0.6150 0.9628 0.2628 0.9730 0.3275 0.8974 0.9029 0.6138 0.7982 0.2331 0.3816 0.3310 0.1081 0.7062 0.5497 0.2387 0.9735 0.1680 0.7839 B(:,:,6) = 0.2888 0.8895 0.4016 0.8029 0.6181 0.2171 0.0189 0.2080 0.6288 0.1967 0.9612 0.1070 0.5867 0.5241 0.6296 0.3558 0.3775 0.8462 0.0671 0.1544 0.5798 0.2676 0.4263 0.5922 0.0850 0.4849 0.9913 0.3701 0.8724 0.0604 0.2887 0.4779 0.1680 0.5676 0.5720 0.7135 0.1695 0.0506 0.3955 0.7007 0.2753 0.4702 0.8408 0.9411 0.8791 0.3929 0.8395 0.8577 0.3466 0.7746 0.4193 0.0782 0.3660 0.6660 0.1029 0.2656 0.5482 0.3079 0.5182 0.6501 0.3278 0.7365 0.1327 0.6828 0.3064 0.5963 0.3465 0.0516 0.3974 0.6445 0.4377 0.2816 0.8109 0.2043 0.4084 0.2671 0.3216 0.8222 0.6356 0.1665 0.6629 0.4967 0.8888 0.4608 0.1331 0.0466 0.3430 0.7564 0.7917 0.2862 0.3687 0.9716 0.6546 0.9616 0.3943 0.5281 0.6333 0.4826 0.1184 0.2487 B(:,:,7) = 0.6608 0.2024 0.2348 0.3396 0.4172 0.8188 0.6907 0.5071 0.8034 0.2568 0.9973 0.5093 0.7559 0.9641 0.1643 0.7621 0.3463 0.9387 0.3932 0.4159 0.2590 0.4603 0.3383 0.4798 0.2135 0.0565 0.7572 0.8719 0.7918 0.4035 0.9955 0.2647 0.7269 0.6130 0.6210 0.4363 0.0726 0.6477 0.8054 0.2065 0.1154 0.7908 0.2506 0.4979 0.5136 0.9052 0.3763 0.8560 0.4274 0.5445 0.9950 0.9462 0.3876 0.7444 0.6350 0.8947 0.4835 0.8595 0.8291 0.6052 0.9403 0.6067 0.3020 0.9616 0.6149 0.6889 0.0246 0.4969 0.4073 0.5361 0.3356 0.8125 0.8935 0.2538 0.9631 0.1385 0.6678 0.1415 0.0944 0.1033 0.5022 0.8880 0.7752 0.1638 0.2459 0.1172 0.1888 0.0282 0.6856 0.6615 0.7264 0.8350 0.5254 0.9044 0.3609 0.5196 0.7213 0.2433 0.9260 0.4064 B(:,:,8) = 0.5487 0.5284 0.9572 0.5234 0.7543 0.3186 0.9580 0.5197 0.9608 0.5057 0.6061 0.4429 0.0017 0.6119 0.0052 0.1035 0.5299 0.5945 0.1375 0.3130 0.6864 0.3610 0.4901 0.5997 0.8997 0.7621 0.3078 0.4389 0.0107 0.5674 0.1503 0.3081 0.1632 0.7851 0.4987 0.5786 0.0555 0.7942 0.0991 0.9807 0.1409 0.8433 0.8969 0.7098 0.4133 0.6404 0.3304 0.5920 0.1152 0.4204 0.4361 0.9501 0.1226 0.6968 0.9440 0.9682 0.8614 0.9085 0.5663 0.5901 0.9907 0.2450 0.8880 0.8036 0.8558 0.0787 0.3143 0.8251 0.0771 0.0099 0.0170 0.3614 0.5364 0.6203 0.5833 0.3925 0.3662 0.4042 0.8797 0.8992 0.4462 0.6729 0.8765 0.7622 0.4138 0.5890 0.0010 0.3514 0.4465 0.9112 0.4585 0.1649 0.4970 0.0391 0.1756 0.5305 0.6427 0.4602 0.4388 0.4683 B(:,:,9) = 0.1662 0.9366 0.8592 0.3003 0.4779 0.3636 0.2024 0.5806 0.2498 0.0425 0.0040 0.4076 0.1203 0.0851 0.9331 0.9410 0.2458 0.8095 0.5243 0.2104 0.6144 0.9947 0.8972 0.8269 0.5883 0.8478 0.8863 0.1800 0.2286 0.9280 0.9177 0.8935 0.8234 0.7370 0.8651 0.6815 0.0658 0.8988 0.1164 0.1390 0.3451 0.4137 0.5483 0.1401 0.6412 0.2723 0.9077 0.3562 0.1028 0.2575 0.5043 0.9847 0.6286 0.3926 0.5448 0.4412 0.8848 0.3073 0.5651 0.0539 0.8590 0.7583 0.3335 0.9182 0.9273 0.7134 0.2155 0.3633 0.3602 0.3566 0.7478 0.2161 0.3749 0.6607 0.5004 0.3694 0.5311 0.4452 0.3418 0.9667 0.4092 0.6735 0.7917 0.0037 0.2215 0.0747 0.1670 0.8858 0.7231 0.9209 0.1605 0.0270 0.5394 0.9175 0.6718 0.7263 0.3557 0.2189 0.2718 0.7373 B(:,:,10) = 0.7568 0.2960 0.4283 0.1470 0.8505 0.8999 0.3310 0.6754 0.9477 0.2297 0.9084 0.4842 0.9956 0.2135 0.4337 0.4485 0.0656 0.6864 0.5570 0.2153 0.7647 0.3727 0.8773 0.4881 0.7318 0.2445 0.7947 0.7196 0.2635 0.9351 0.9077 0.6582 0.9732 0.0719 0.3034 0.3169 0.7108 0.8495 0.0710 0.8157 0.8788 0.5393 0.6715 0.5149 0.7280 0.2304 0.7554 0.7415 0.5675 0.5939 0.9157 0.1804 0.7801 0.5974 0.3544 0.1250 0.0106 0.9462 0.0206 0.5083 0.1869 0.7258 0.8645 0.3030 0.5680 0.0969 0.1198 0.7025 0.6287 0.5995 0.3574 0.0188 0.6472 0.5461 0.1499 0.1853 ...

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

### Community Treasure Hunt

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

Start Hunting!