Cody

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

Solution 2561013

Submitted on 15 Jun 2020 by Juan Berjón Díez
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.8589 0.3297 0.0564 0.2691 0.8986 0.8817 0.1709 0.6364 0.2682 0.6951 0.8647 0.5260 0.1956 0.9537 0.3081 0.4081 0.7541 0.9105 0.8737 0.5680 0.8453 0.3767 0.3552 0 0.9386 0.0003 0.0265 0.3839 0.9303 0.3176 0.0972 0.8091 0.1139 0.6458 0.4309 0.4265 0.5331 0.9280 0.6103 0.1100 0.3324 0.4871 0.4742 0.8972 0.2063 0.6816 0.7071 0.4211 0.0490 0.9534 0.9458 0.8278 0.9706 0.9706 0.3012 0.5255 0.5495 0.9726 0.2521 0.3844 0.3897 0.2181 0.3545 0.8670 0.3155 0.5282 0.5853 0.3459 0.4867 0.2595 0.5363 0.8729 0.3515 0.1040 0.8426 0.3797 0.8660 0.3054 0.7554 0.8028 0.6219 0.3660 0.6372 0.0249 0.0822 0.8918 0.9020 0.7843 0.5334 0.4232 0.2329 0.3372 0.2633 0.5253 0.6978 0.5973 0.9369 0.2736 0.7665 0.0867 B(:,:,2) = 0.1907 0 0.6446 0.9716 0.5089 0.9168 0.2034 0.3574 0.2862 0.5059 0.2820 0.7881 0.3450 0.8648 0.4410 0.8454 0.0616 0.5814 0.0522 0.2778 0.9525 0.7188 0.0847 0.6173 0.0949 0.1777 0.9852 0.7534 0.0631 0.5388 0.0066 0.0451 0.6200 0.0985 0.0705 0.2818 0.4146 0.4719 0.8605 0.4196 0.9690 0.3098 0.1719 0.7791 0.7443 0.0309 0.3903 0.2225 0.3789 0.8773 0.6644 0.1636 0.4373 0.9215 0.6773 0.9400 0.1711 0.5712 0.4996 0.0917 0.8520 0.8814 0.7102 0.5396 0.5263 0.8294 0.0220 0.0400 0.1428 0.0148 0.7016 0.3963 0.1245 0.4231 0.8057 0.2687 0.1222 0.6365 0.8051 0.3568 0.3823 0.1893 0.3674 0.1921 0.4590 0.4701 0.8347 0.8060 0.5942 0.3854 0.5104 0.1648 0.8928 0.8646 0.9237 0.0634 0.1244 0.5474 0.4457 0.8285 B(:,:,3) = 0.3438 0.1481 0.8232 0.1906 0.5851 0.0734 0.3527 0.7283 0.4574 0.2725 0.8857 0.3748 0.2426 0.7608 0.5697 0.4220 0.5770 0.6435 0.3435 0.2349 0.6756 0.5663 0.5296 0.5156 0.3156 0.5075 0.6557 0.5636 0.8331 0.5553 0.3842 0.3500 0.3314 0.1766 0.1877 0.1695 0.7206 0.1447 0.0671 0.5004 0.0649 0.4662 0.2215 0.4047 0.9819 0 0.7256 0.2095 0.9387 0.2456 0.8601 0.9571 0.7780 0.7779 0.2044 0.9167 0.8182 0.4211 0.8205 0.8321 0.5764 0.0848 0.6183 0.4612 0.1103 0.4826 0.2214 0.9425 0.1762 0.1171 0.8641 0.0040 0.6219 0.2280 0.4962 0.9175 0.3661 0.3034 0.1977 0.5345 0.4533 0.7120 0.5162 0.5114 0.7585 0.8915 0.8894 0.7156 0.4897 0.3057 0.4888 0.5688 0.1684 0.5486 0.9095 0.5472 0.6623 0.0309 0.5550 0.0270 B(:,:,4) = 0.5537 0.0455 0.2579 0.6577 0.0092 0.6823 0.3764 0.7496 0.9033 0.9841 0.6317 0.6278 0.4384 0.7387 0.0753 0.8992 0.9112 0.5137 0.4341 0.3412 0.4404 0.6329 0.3463 0.9756 0.9771 0.3700 0.8048 0.3948 0.8419 0.6958 0.5521 0.0093 0.7053 0.4824 0.2051 0.8686 0.1108 0.1439 0.8044 0.4936 0.4379 0.6711 0.9343 0.0353 0.3491 0.3526 0.7405 0.3212 0.3485 0.4987 0.7454 0.9828 0.1578 0.7920 0.9163 0.9540 0.3047 0.1578 0.0600 0.9259 0.2182 0.8054 0.0504 0.6581 0.0149 0.0613 0.8087 0.6603 0.3673 0.5721 0.3090 0.1145 0.0474 0.6402 0.0810 0.9864 0.4263 0.7635 0.5764 0.4030 0.1422 0.1358 0.8014 0.4065 0.5238 0.6325 0.9948 0.5885 0.3994 0.9425 0.8892 0.9586 0.1953 0.9421 0.3884 0.5383 0.5771 0.3309 0.2541 0.9191 B(:,:,5) = 0.9780 0.5994 0.7372 0.1586 0.2104 0.0449 0.6704 0.7448 0.2003 0.6606 0.9778 0.7637 0.0444 0.6998 0.9825 0.4459 0.8035 0.2120 0.6656 0.6992 0.9690 0.3729 0.7648 0.0569 0.1919 0.9640 0.2306 0.1003 0.3520 0.5178 0.2431 0.4042 0.0644 0.9952 0.3974 0.4718 0.7477 0.9857 0.3729 0.7371 0.9095 0.6044 0.9810 0.5818 0.8602 0.5232 0.0022 0.6418 0.2568 0.2406 0.6900 0.5474 0.9520 0.0974 0.3175 0.8810 0.6707 0.5727 0.3325 0.1139 0.3789 0.4141 0.4635 0.3260 0.6287 0.4662 0.2562 0.2874 0.8217 0.1183 0.8398 0.8699 0.3108 0.4287 0.5653 0.3239 0.6654 0.4222 0.7448 0.5701 0.5303 0.9033 0.0250 0.3870 0.3575 0.7192 0.2869 0.9983 0.6159 0.6461 0.5205 0.2826 0.0395 0.8303 0.0681 0.0468 0.0229 0.1405 0.8714 0.2281 B(:,:,6) = 0.7040 0.5256 0.3209 0.0010 0.3114 0.6937 0.0492 0.0002 0.1811 0.9861 0.0947 0.4349 0.7004 0.0730 0.8890 0.4684 0.8445 0.7543 0.2358 0.7785 0.1166 0.6802 0.6929 0.9614 0.0279 0.0134 0.5472 0.1321 0.8362 0.3236 0.4843 0.0313 0.8803 0.7239 0.0277 0.7083 0.5018 0.2150 0.0936 0.2820 0.0152 0.6826 0.7710 0.4926 0.0653 0.1085 0.6576 0.5440 0.3550 0.5921 0.5347 0.9572 0.6458 0.5544 0.8067 0.8116 0.5936 0.4258 0.0161 0.8483 0.8679 0.4501 0.1323 0.6063 0.7552 0.9943 0.7964 0.4173 0.9910 0.0176 0.5089 0.6689 0.9029 0.5976 0.1284 0.4769 0.8687 0.6484 0.6944 0.1169 0.4923 0.1886 0.5939 0.6963 0.2202 0.8038 0.1829 0.7981 0.9776 0.4667 0.6001 0.8594 0.8989 0.4546 0.2075 0.9261 0.4848 0.6384 0.1507 0.8191 B(:,:,7) = 0.8726 0.9955 0.9734 0.5748 0.6846 0.6376 0.9082 0.3508 0.7800 0.4151 0.7426 0.6713 0.4007 0.1791 0.1703 0.5604 0.2919 0.6492 0.3617 0.3567 0.1764 0.7636 0.5545 0.0408 0.6321 0.4427 0.5195 0.2576 0.2856 0.5568 0.7463 0.1252 0.7409 0.2417 0.9719 0.6530 0.8301 0.1344 0.5251 0.0585 0.5323 0.7099 0.9788 0.8309 0.2237 0.0161 0.1176 0.1816 0.8849 0.7326 0.4848 0.3095 0.7830 0.4327 0.7422 0.7621 0.2566 0.5292 0.5369 0.8148 0.1043 0.1570 0.1826 0.7386 0.7544 0.7612 0.9932 0.4478 0.8370 0.7910 0.0885 0.2333 0.7032 0.7621 0.2744 0.8764 0.1127 0.1807 0.3997 0.6335 0.5669 0.3181 0.2219 0.7819 0.7482 0.9097 0.0781 0.6975 0.3856 0.1154 0.6549 0.3757 0.3071 0.1551 0.7929 0.3888 0.5085 0.5326 0.0593 0.3832 B(:,:,8) = 0.0266 0.5427 0.5351 0.6528 0.3313 0.1130 0.0755 0.1434 0.0446 0.8153 0.3762 0.9634 0.1307 0.7005 0.5194 0.5872 0.5837 0.4066 0.9374 0.5551 0.0008 0.4439 0.6361 0.9408 0.8958 0.1141 0.3289 0.2037 0.9820 0.7443 0.6418 0.9798 0.7382 0.8779 0.6758 0.6515 0.8829 0.6504 0.2909 0.4159 0.5335 0.5969 0.9006 0.2092 0.8679 0.1510 0.0538 0.4287 0.1423 0.2532 0.4612 0.9563 0.8305 0.4287 0.3840 0.9318 0.2069 0.7697 0.2342 0.0325 0.7365 0.3650 0.1023 0.2350 0.0581 0.0750 0.7459 0.2951 0.4972 0.8335 0.9297 0.2487 0.1869 0.1958 0.0082 0.6873 0.8303 0.0199 0.9530 0.7674 0.4671 0.4764 0.5810 0.9820 0.6197 0.3812 0.6455 0.5572 0.6457 0.0268 0.6507 0.9706 0.9730 0.5285 0.6952 0.7091 0.6238 0.3246 0.0001 0.1908 B(:,:,9) = 0.1931 0.8867 0.5631 0.3421 0.1275 0.9255 0.4328 0.0285 0.5628 0.5356 0.6832 0.2301 0.8611 0.1751 0.3636 0.2407 0.6396 0.9977 0.7273 0.7773 0.1327 0.8738 0.6986 0.8900 0.1265 0.3614 0.5319 0.7041 0.8758 0.0927 0.5492 0.6684 0.9503 0.5611 0.3558 0.9546 0.8476 0.7308 0.9666 0.5011 0.5029 0.7023 0.2831 0.2216 0.5432 0.3061 0.1405 0.5656 0.8999 0.4018 0.4205 0.1341 0.1157 0.1162 0.4090 0.2868 0.7158 0.7403 0.0564 0.2011 0.4592 0.0147 0.5340 0.0064 0.8394 0.2630 0.7392 0.2187 0.1391 0.5043 0.3664 0.1810 0.0767 0.5481 0.4934 0.9177 0.5923 0.5118 0.8386 0.9340 0.8679 0.2540 0.9188 0.7456 0.1218 0.0752 0.5988 0.5209 0.4920 0.2867 0.9139 0.9186 0.2981 0.8343 0.5764 0.3239 0.8813 0.8050 0.5428 0.0330 B(:,:,10) = 0.1244 0.9302 0.0342 0.7511 0.0608 0.6624 0.0710 0.4625 0.8822 0.7699 0.2208 0.8689 0.0407 0.4219 0.0817 0.3952 0.1521 0.2585 0.1867 0.1638 0.7916 0.1427 0.4622 0.3554 0.1184 0.9465 0.0839 0.9514 0.7282 0.4953 0.5239 0.7161 0.7145 0.1202 0.1785 0.2751 0.5052 0.2405 0.5483 0.1332 0.5154 0.8981 0.2578 0.0606 0.9660 0.8837 0.4601 0.2742 0.5171 0.4928 0.7992 0.8117 0.2676 0.8834 0.9228 0.2488 0.4659 0.2307 0.9865 0.7166 0.7598 0.0442 0.8279 0.5938 0.9270 0.0874 0.5442 0.9476 0.9478 0.3649 0.1709 0.2381 0.7782 0.8270 0.7171 0.3861 ...

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

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!