Cody

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

Solution 2049088

Submitted on 6 Dec 2019 by LNG
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.3658 0.1405 0.2411 0.3893 0.8633 0.4169 0.6358 0.0491 0.5540 0.2997 0.0843 0.3787 0.9028 0.0431 0.7803 0.1868 0.1410 0.4798 0.3458 0.3740 0.0365 0.8468 0.8480 0 0.7044 0.3805 0.1857 0.4355 0.1749 0.7041 0.2696 0.1083 0.5416 0.4204 0.1113 0.5657 0.4978 0.0445 0.6223 0.7344 0.8187 0.7754 0.2679 0.2309 0.5828 0.3143 0.7374 0.5525 0.2549 0.3940 0.1334 0.9458 0.6069 0.7322 0.1554 0.1506 0.0070 0.0507 0.1024 0.1106 0.1144 0.0031 0.7540 0.7570 0.8366 0.5468 0.1363 0.7860 0.5294 0.7750 0.6795 0.4319 0.4367 0.0705 0.5577 0.9050 0.8136 0.4758 0.4942 0.8852 0.8442 0.3229 0.4660 0.3667 0.5197 0.5706 0.1504 0.6077 0.6905 0.1946 0.6767 0.0481 0.8856 0.6304 0.1229 0.9595 0.1090 0.1814 0.2372 0.6014 B(:,:,2) = 0.0671 0 0.1815 0.4307 0.5437 0.3240 0.9682 0.7264 0.3527 0.1051 0.1428 0.6254 0.2463 0.9568 0.4113 0.0584 0.9601 0.8198 0.8388 0.5906 0.8802 0.1746 0.4398 0.0590 0.1052 0.4412 0.9531 0.6128 0.9551 0.4696 0.7492 0.5032 0.9410 0.5169 0.3244 0.2438 0.3404 0.6706 0.0708 0.3446 0.5337 0.8886 0.5924 0.4783 0.1141 0.7034 0.9035 0.0729 0.4905 0.6250 0.4239 0.9938 0.1285 0.6269 0.0370 0.6469 0.0594 0.7390 0.4476 0.3944 0.9960 0.5982 0.2383 0.6864 0.4347 0.2702 0.6772 0.1885 0.5369 0.5157 0.8249 0.9994 0.7887 0.7222 0.2449 0.5889 0.8061 0.0868 0.2478 0.8571 0.6810 0.6579 0.5353 0.8568 0.3489 0.3227 0.3151 0.0249 0.9540 0.9362 0.0211 0.7917 0.1196 0.7043 0.5676 0.2112 0.8786 0.6461 0.8549 0.3062 B(:,:,3) = 0.1157 0.6711 0.3372 0.6559 0.0704 0.9555 0.9697 0.7168 0.0586 0.5820 0.5532 0.5720 0.6850 0.6692 0.4867 0.1536 0.2546 0.2036 0.6386 0.2732 0.6157 0.5223 0.0597 0.5942 0.3459 0.9835 0.6525 0.4238 0.8806 0.2635 0.8759 0.2392 0.5422 0.6369 0.9376 0.7612 0.5477 0.6294 0.0615 0.0240 0.4722 0.6587 0.4344 0.4595 0.0444 0 0.5234 0.0013 0.0263 0.7001 0.1796 0.1459 0.4225 0.4438 0.4347 0.7202 0.1888 0.6771 0.8968 0.9199 0.7839 0.5487 0.7002 0.3163 0.6968 0.8798 0.0998 0.5335 0.9349 0.7837 0.3869 0.7459 0.3032 0.4942 0.9754 0.3311 0.2101 0.6167 0.3903 0.2526 0.0770 0.2814 0.7065 0.1921 0.2629 0.5211 0.1976 0.7980 0.4360 0.9046 0.2468 0.8037 0.5593 0.4136 0.5740 0.9762 0.6081 0.9772 0.7962 0.2983 B(:,:,4) = 0.6937 0.9366 0.0666 0.3319 0.2345 0.7119 0.0218 0.5977 0.5043 0.0463 0.7013 0.3685 0.9495 0.5992 0.1131 0.9033 0.2100 0.2493 0.8601 0.1917 0.8113 0.2812 0.8020 0.8116 0.8271 0.9609 0.1575 0.5545 0.8811 0.8839 0.4867 0.5054 0.5714 0.8556 0.6855 0.3209 0.3505 0.4095 0.6463 0.8827 0.7642 0.6737 0.1588 0.4893 0.4450 0.7536 0.1193 0.5085 0.6222 0.2795 0.0798 0.1115 0.7407 0.3220 0.8650 0.5886 0.6283 0.1537 0.6197 0.7782 0.1744 0.2713 0.1202 0.6529 0.1986 0.2020 0.0359 0.5979 0.1051 0.4806 0.1397 0.4432 0.0424 0.3775 0.3164 0.6067 0.3643 0.8177 0.4851 0.2337 0.2944 0.8742 0.6790 0.0426 0.6299 0.8054 0.2650 0.7359 0.0949 0.3075 0.7569 0.7872 0.1178 0.1597 0.4782 0.9676 0.4350 0.7434 0.9311 0.4267 B(:,:,5) = 0.8681 0.8503 0.7163 0.4860 0.4936 0.0633 0.4779 0.1327 0.8042 0.3914 0.5086 0.5604 0.4280 0.7613 0.5856 0.4925 0.1671 0.5909 0.1050 0.1910 0.2018 0.8521 0.7455 0.5506 0.7746 0.7397 0.4808 0.6917 0.2497 0.5985 0.7955 0.5481 0.8446 0.9673 0.7935 0.8255 0.1009 0.2407 0.6840 0.5030 0.9672 0.6186 0.9679 0.0758 0.3657 0.2872 0.7526 0.0644 0.1211 0.2037 0.5720 0.8604 0.9606 0.4880 0.5705 0.2206 0.4825 0.7631 0.6583 0.6335 0.7188 0.4792 0.2947 0.2567 0.2289 0.9923 0.1256 0.9251 0.8611 0.5129 0.6099 0.7406 0.6531 0.4061 0.8455 0.6594 0.7062 0.1309 0.4123 0.0114 0.0001 0.7265 0.0110 0.0594 0.5776 0.8065 0.2597 0.7373 0.2990 0.6316 0.2174 0.4851 0.5405 0.6155 0.0656 0.0029 0.5731 0.8169 0.4121 0.4601 B(:,:,6) = 0.2635 0.4366 0.7322 0.5233 0.6091 0.2997 0.4143 0.7766 0.5781 0.5277 0.4318 0.9200 0.6136 0.4099 0.0080 0.6379 0.1876 0.3803 0.6814 0.9489 0.5792 0.2632 0.3362 0.0812 0.5571 0.6557 0.1530 0.0740 0.3267 0.6074 0.7753 0.6219 0.8283 0.3837 0.8683 0.6907 0.4241 0.3519 0.4677 0.6056 0.8313 0.1455 0.3940 0.2348 0.6612 0.8130 0.6803 0.9226 0.8572 0.1581 0.5732 0.3806 0.6415 0.7925 0.9693 0.9907 0.1490 0.8373 0.6404 0.1469 0.2648 0.9367 0.1687 0.6021 0.2763 0.1891 0.0659 0.4418 0.6896 0.6883 0.9076 0.1702 0.8718 0.3400 0.5061 0.0894 0.0555 0.1594 0.6118 0.6276 0.2769 0.0277 0.1331 0.7094 0.1876 0.6425 0.8364 0.1755 0.3638 0.0650 0.0672 0.8108 0.2105 0.8424 0.5541 0.4842 0.8367 0.1814 0.3125 0.3058 B(:,:,7) = 0.6203 0.3664 0.1474 0.6950 0.5193 0.2132 0.0596 0.3199 0.4070 0.5279 0.6950 0.4106 0.5040 0.1548 0.0595 0.6233 0.0371 0.0802 0.0301 0.8286 0.8537 0.0496 0.3850 0.4195 0.8963 0.3252 0.0540 0.5733 0.9023 0.6336 0.6553 0.7718 0.4515 0.8361 0.4557 0.8403 0.5083 0.4628 0.7489 0.1934 0.3248 0.1305 0.9300 0.6891 0.9614 0.7137 0.9394 0.7554 0.4754 0.2680 0.3822 0.1915 0.6819 0.9450 0.7613 0.8139 0.7842 0.4129 0.6018 0.1491 0.2928 0.4178 0.2576 0.0261 0.8742 0.4791 0.4354 0.8150 0.0863 0.2724 0.0140 0.1051 0.3461 0.5444 0.9124 0.7082 0.3724 0.0712 0.8881 0.6483 0.9069 0.8660 0.4262 0.0654 0.6746 0.2558 0.6546 0.9171 0.7829 0.7047 0.9928 0.2521 0.3471 0.2326 0.1702 0.0738 0.1083 0.0782 0.1512 0.2597 B(:,:,8) = 0.7691 0.9733 0.1942 0.8689 0.7888 0.3874 0.4208 0.4246 0.2577 0.9798 0.8295 0.8572 0.1099 0.1776 0.1987 0.0583 0.3853 0.6303 0.5590 0.3329 0.3418 0.5521 0.5615 0.2793 0.7081 0.2349 0.2647 0.0808 0.9894 0.3387 0.1713 0.2127 0.7285 0.6758 0.1767 0.5221 0.6512 0.3477 0.7937 0.3600 0.1723 0.6498 0.9103 0.0873 0.6439 0.4871 0.9126 0.0781 0.9281 0.4611 0.4264 0.9849 0.1779 0.6637 0.0182 0.3098 0.1726 0.6982 0.2028 0.5586 0.8533 0.8633 0.2031 0.6888 0.3641 0.7405 0.8655 0.6245 0.9326 0.5094 0.6189 0.5802 0.9724 0.0212 0.5548 0.6896 0.0288 0.7689 0.5626 0.2105 0.7187 0.8655 0.7019 0.3819 0.8187 0.2657 0.2342 0.2234 0.4980 0.4401 0.7528 0.3534 0.5703 0.9565 0.8182 0.6493 0.7639 0.1155 0.6027 0.5113 B(:,:,9) = 0.9145 0.6137 0.9078 0.8207 0.7831 0.4685 0.4588 0.3526 0.9002 0.5930 0.3147 0.4206 0.2213 0.2445 0.4035 0.9619 0.8227 0.3226 0.5567 0.7382 0.3429 0.0039 0.4269 0.7489 0.9290 0.2735 0.5824 0.9551 0.1865 0.7176 0.7542 0.9482 0.3081 0.7187 0.0355 0.9849 0.6010 0.5783 0.0186 0.6233 0.9419 0.7653 0.2905 0.6498 0.1886 0.4680 0.9033 0.8442 0.2933 0.2024 0.4528 0.1892 0.9376 0.3024 0.3994 0.0596 0.5283 0.3793 0.6015 0.5232 0.0716 0.9872 0.5551 0.9774 0.1461 0.4791 0.4759 0.0315 0.7412 0.2912 0.4311 0.8473 0.6417 0.7436 0.4150 0.2518 0.2054 0.0711 0.9969 0.3433 0.1908 0.6153 0.7244 0.3018 0.4108 0.6281 0.6114 0.4843 0.7703 0.8314 0.1243 0.9715 0.2015 0.2146 0.5721 0.6551 0.9721 0.8916 0.2280 0.8356 B(:,:,10) = 0.2552 0.4087 0.0910 0.2276 0.7004 0.8414 0.7149 0.6328 0.3308 0.9036 0.7504 0.5903 0.2546 0.6821 0.3605 0.9081 0.0441 0.8166 0.3637 0.8921 0.5327 0.3644 0.1510 0.0185 0.6860 0.9658 0.3120 0.0583 0.9607 0.7836 0.3854 0.3315 0.7830 0.2226 0.4399 0.1631 0.0162 0.5198 0.7460 0.4275 0.5285 0.0122 0.0137 0.8577 0.5150 0.9709 0.0254 0.4075 0.0239 0.0753 0.7799 0.1434 0.8244 0.4599 0.0216 0.5769 0.1272 0.8510 0.9496 0.5024 0.0870 0.0023 0.5119 0.9742 0.8175 0.2463 0.3690 0.8638 0.2238 0.4066 0.9587 0.8862 0.3686 0.4044 0.3824 0.9868 ...

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

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!