Cody

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

Solution 2897582

Submitted on 1 Sep 2020 by David K
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.4901 0.0229 0.2105 0.0926 0.6941 0.6880 0.0042 0.7409 0.7259 0.3231 0.8944 0.6776 0.2070 0.5940 0.2320 0.3827 0.7858 0.3695 0.8095 0.7713 0.8932 0.7374 0.4309 0 0.0747 0.9388 0.3366 0.4676 0.8337 0.8067 0.8517 0.9046 0.5583 0.4645 0.0910 0.8845 0.5140 0.8866 0.5836 0.2910 0.8379 0.7120 0.7676 0.7102 0.9898 0.0410 0.2645 0.9784 0.4157 0.0524 0.6713 0.1166 0.1369 0.7173 0.4100 0.9572 0.0876 0.1446 0.7132 0.4601 0.2928 0.9152 0.2014 0.5379 0.8721 0.8718 0.3807 0.6547 0.5936 0.1115 0.8132 0.4576 0.1469 0.1181 0.6781 0.8829 0.6011 0.8631 0.6809 0.0609 0.5893 0.6391 0.7322 0.1912 0.8628 0.3506 0.5266 0.7449 0.4905 0.0077 0.4185 0.7871 0.5260 0.1233 0.2880 0.0294 0.0866 0.7089 0.3416 0.2185 B(:,:,2) = 0.4057 0 0.8228 0.8290 0.4344 0.9775 0.8067 0.4571 0.0877 0.3352 0.3236 0.7435 0.4420 0.7690 0.8247 0.8069 0.7562 0.5044 0.7303 0.8935 0.4682 0.7147 0.0318 0.5523 0.9583 0.0717 0.6816 0.2565 0.9404 0.7780 0.6645 0.1816 0.0320 0.4344 0.2803 0.1343 0.4917 0.5124 0.5845 0.6655 0.6773 0.5912 0.0517 0.0051 0.3261 0.6619 0.9327 0.6458 0.7397 0.7111 0.3708 0.1608 0.8066 0.4626 0.1504 0.0823 0.9235 0.6256 0.5152 0.8714 0.2538 0.5495 0.8552 0.8361 0.8443 0.5484 0.4117 0.1287 0.2991 0.5679 0.7528 0.7427 0.2188 0.1917 0.7043 0.5204 0.2547 0.5410 0.1432 0.4806 0.3686 0.8020 0.9802 0.1683 0.8493 0.1860 0.4282 0.4716 0.9994 0.0890 0.0696 0.4895 0.0113 0.8899 0.3881 0.6544 0.8858 0.9132 0.2329 0.4001 B(:,:,3) = 0.9289 0.5862 0.8611 0.6649 0.2499 0.7733 0.6332 0.7056 0.7106 0.6058 0.5174 0.5741 0.9770 0.7963 0.3906 0.2140 0.7351 0.8245 0.2286 0.1171 0.0840 0.7625 0.8509 0.6549 0.2938 0.6885 0.5473 0.3483 0.2942 0.8352 0.9582 0.4055 0.5418 0.5190 0.5285 0.9119 0.5602 0.8188 0.3178 0.9143 0.6435 0.6907 0.2655 0.5300 0.5543 0 0.4426 0.8651 0.3872 0.2514 0.9622 0.0293 0.0298 0.9081 0.2551 0.5643 0.6086 0.4894 0.8445 0.1847 0.7771 0.9576 0.0943 0.5696 0.6386 0.9103 0.7256 0.3687 0.4414 0.1976 0.7163 0.0550 0.7164 0.1975 0.9086 0.4837 0.1003 0.7941 0.3803 0.1322 0.3001 0.1334 0.6711 0.5205 0.3665 0.7334 0.6510 0.2752 0.4078 0.8211 0.2021 0.9462 0.9393 0.9550 0.9119 0.5715 0.5082 0.9928 0.2348 0.8331 B(:,:,4) = 0.4353 0.1491 0.2370 0.5440 0.8673 0.0549 0.9640 0.7373 0.9174 0.8071 0.7991 0.7679 0.1868 0.5778 0.0702 0.3816 0.9426 0.9073 0.4424 0.1491 0.7853 0.9921 0.5916 0.5155 0.9539 0.1324 0.8440 0.9875 0.6159 0.9252 0.9431 0.3450 0.3436 0.9347 0.4222 0.3018 0.4823 0.1699 0.5979 0.2495 0.0455 0.4186 0.1152 0.4423 0.3497 0.1625 0.0816 0.8277 0.4069 0.0895 0.7878 0.9830 0.5743 0.1811 0.1433 0.2995 0.4472 0.1321 0.9162 0.1124 0.3764 0.1241 0.0645 0.6424 0.4506 0.8288 0.8642 0.0808 0.0283 0.5707 0.9660 0.2484 0.3308 0.2772 0.9563 0.1987 0.2814 0.2412 0.3455 0.0719 0.5547 0.5808 0.6248 0.8525 0.1708 0.2942 0.2641 0.5199 0.7322 0.0644 0.6990 0.3941 0.2410 0.8463 0.0203 0.9306 0.4508 0.4522 0.4581 0.3182 B(:,:,5) = 0.5953 0.6993 0.9469 0.2453 0.1015 0.9078 0.9723 0.5073 0.5465 0.6593 0.1770 0.2918 0.0848 0.3220 0.1749 0.9220 0.2412 0.7718 0.6296 0.8768 0.7418 0.9827 0.1242 0.7380 0.9393 0.8790 0.3160 0.4481 0.4617 0.0584 0.2291 0.4697 0.1183 0.9317 0.2851 0.1460 0.3058 0.1298 0.1969 0.6031 0.6834 0.1738 0.3476 0.4269 0.7019 0.7453 0.0972 0.3648 0.8204 0.6963 0.5744 0.4564 0.4145 0.9239 0.8618 0.4400 0.1045 0.3982 0.4874 0.8060 0.7509 0.9081 0.9492 0.3828 0.5661 0.4921 0.9245 0.7549 0.5424 0.6123 0.1125 0.8832 0.3890 0.5152 0.1488 0.0913 0.2496 0.6279 0.9652 0.9359 0.1913 0.5607 0.2608 0.6052 0.1178 0.5436 0.5247 0.3630 0.3114 0.5726 0.6464 0.8100 0.1709 0.4623 0.9831 0.8071 0.5722 0.9133 0.5737 0.3948 B(:,:,6) = 0.3963 0.1821 0.0530 0.3415 0.5144 0.8035 0.0222 0.4672 0.9949 0.7319 0.2386 0.1676 0.5045 0.7351 0.4776 0.6861 0.1570 0.5396 0.6257 0.6241 0.3721 0.5997 0.6727 0.6528 0.5170 0.6148 0.6754 0.2929 0.4525 0.6720 0.1929 0.8439 0.4124 0.5328 0.4520 0.8873 0.0264 0.9440 0.2609 0.0060 0.9277 0.1935 0.5774 0.4555 0.2983 0.5305 0.1992 0.3527 0.5362 0.9972 0.1207 0.7908 0.2008 0.4681 0.8000 0.2839 0.0539 0.7811 0.1503 0.6806 0.8324 0.2181 0.2595 0.4936 0.8986 0.9288 0.7858 0.7148 0.7147 0.0887 0.1356 0.8298 0.6835 0.6075 0.2379 0.4204 0.9164 0.6841 0.3981 0.9656 0.8519 0.1780 0.0327 0.6016 0.7119 0.0219 0.9308 0.7993 0.2979 0.5208 0.9574 0.3084 0.1365 0.5154 0.7783 0.3033 0.8049 0.5966 0.7220 0.2484 B(:,:,7) = 0.9519 0.7617 0.4355 0.6269 0.2845 0.3415 0.1584 0.1198 0.6899 0.7940 0.2674 0.1935 0.2089 0.4527 0.7809 0.8241 0.7526 0.7422 0.7917 0.4752 0.3009 0.8700 0.2461 0.8092 0.0737 0.3524 0.8717 0.9190 0.9528 0.2176 0.9791 0.0518 0.4344 0.2122 0.0987 0.0548 0.1446 0.4264 0.2593 0.8578 0.3541 0.3136 0.6282 0.7924 0.9764 0.7926 0.0471 0.7323 0.8763 0.2886 0.7720 0.4097 0.1118 0.0118 0.8893 0.5287 0.8418 0.9890 0.3212 0.1271 0.4402 0.5779 0.0180 0.1087 0.8744 0.9522 0.3407 0.6885 0.4129 0.1456 0.5840 0.1528 0.0233 0.3358 0.9985 0.6295 0.3342 0.5572 0.9175 0.4381 0.9275 0.4158 0.0470 0.2154 0.1359 0.6110 0.9711 0.1267 0.2943 0.2913 0.1434 0.7289 0.0417 0.3733 0.0886 0.6323 0.4846 0.3263 0.3758 0.2216 B(:,:,8) = 0.7984 0.3474 0.2148 0.6564 0.0564 0.9171 0.1869 0.7210 0.6855 0.1586 0.1240 0.1753 0.6961 0.6786 0.5191 0.6064 0.8326 0.1132 0.9526 0.3519 0.3815 0.8793 0.1318 0.9991 0.1616 0.5120 0.7559 0.8617 0.2373 0.0536 0.7532 0.2180 0.9729 0.4896 0.5503 0.0268 0.4821 0.2907 0.9280 0.5512 0.4627 0.5818 0.4359 0.1053 0.9289 0.5909 0.4758 0.9500 0.1400 0.6452 0.9805 0.9512 0.7077 0.6973 0.4473 0.5372 0.9735 0.9677 0.5414 0.1588 0.4131 0.8184 0.6214 0.6111 0.6340 0.8589 0.9126 0.7651 0.5335 0.9606 0.7735 0.2194 0.2115 0.1243 0.3140 0.6767 0.4897 0.1293 0.0469 0.5925 0.5297 0.7464 0.4270 0.5566 0.4095 0.5681 0.3608 0.6283 0.6111 0.6482 0.5885 0.6762 0.9944 0.9535 0.9474 0.9122 0.1221 0.0978 0.9983 0.5912 B(:,:,9) = 0.2525 0.1051 0.1340 0.1019 0.1216 0.0164 0.9793 0.9375 0.2997 0.9778 0.8700 0.2952 0.0077 0.4028 0.2218 0.4306 0.4130 0.7102 0.4700 0.5999 0.8080 0.9833 0.7921 0.5954 0.3278 0.8148 0.0564 0.5825 0.6321 0.8351 0.4167 0.9900 0.9814 0.1574 0.9066 0.0991 0.6311 0.2460 0.8064 0.8210 0.7514 0.9226 0.7576 0.2893 0.0320 0.3281 0.0158 0.9948 0.1153 0.7113 0.4783 0.2356 0.9467 0.0639 0.2139 0.9808 0.9310 0.8764 0.4279 0.5211 0.9364 0.7818 0.7811 0.4454 0.4145 0.0268 0.5771 0.3173 0.3284 0.4851 0.1375 0.1318 0.3033 0.7904 0.4208 0.1332 0.7028 0.2338 0.6520 0.2693 0.0589 0.7497 0.6850 0.5478 0.6479 0.2158 0.6494 0.0441 0.0264 0.3969 0.8059 0.7853 0.2213 0.1657 0.7688 0.8421 0.0669 0.4269 0.4832 0.6283 B(:,:,10) = 0.7698 0.1507 0.9452 0.7276 0.9836 0.2864 0.3662 0.1655 0.9915 0.5658 0.9639 0.3312 0.9628 0.8696 0.3294 0.7702 0.8196 0.9455 0.3830 0.2917 0.6527 0.8345 0.0650 0.6107 0.5204 0.9578 0.7925 0.4406 0.9503 0.3144 0.9048 0.6590 0.3731 0.7271 0.3625 0.3204 0.1939 0.7739 0.3407 0.2064 0.7993 0.2366 0.6490 0.8957 0.5124 0.0217 0.2201 0.5044 0.6391 0.5272 0.8825 0.4431 0.3120 0.6834 0.0680 0.6180 0.2553 0.1264 0.2756 0.4889 0.1353 0.3371 0.6488 0.3403 0.1209 0.0158 0.9735 0.6796 0.9415 0.4390 0.1403 0.1826 0.9685 0.3016 0.2699 0.2085 ...

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

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!