Cody

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

Solution 486353

Submitted on 14 Aug 2014 by bainhome
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
%% test 1 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')

A = 15 0 3

2   Pass
%% test 2 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

3   Pass
%% test 3 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')

A = []

4   Pass
%% test 4 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')

A = 0 0 0 0 0 8 0 25 2

5   Pass
%% test 5 with a multidimensional array 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')

A(:,:,1) = Columns 1 through 9 0.2778 0.4689 0.1711 0.1506 0.2566 0.5383 0.9986 0.7938 0.4760 0.7147 0.9053 0.9234 0.5580 0.7958 0.8667 0.3842 0.4649 0.6680 0.0103 0.7028 0.9562 0 0.4025 0.0168 0.8936 0.7887 0.3981 0.7691 0.1564 0.2882 0.3605 0.1650 0.9077 0.3310 0.5872 0.4239 0.9984 0.7677 0.8848 0.3705 0.3883 0.2252 0.9742 0.7901 0.7207 0.3061 0.5321 0.4653 0.6185 0.3669 0.4062 0.9455 0.1500 0.2867 0.8124 0.0097 0.9847 0.0044 0.4350 0.0513 0.0075 0.4224 0.0022 0.6314 0.2627 0.0636 0.6315 0.2537 0.7071 0.7505 0.8233 0.4350 0.5210 0.3646 0.5045 0.8739 0.6814 0.4457 0.2428 0.3691 0.7881 0.5480 0.6230 0.9979 0.9419 0.1675 0.3654 0.3442 0.0522 0.1401 Column 10 0.3851 0.4259 0.2218 0.8674 0.1417 0.6818 0.0325 0.9290 0.7024 0.2093 A(:,:,2) = Columns 1 through 9 0.0120 0 0.7408 0.9685 0.5397 0.6206 0.2699 0.4458 0.8785 0.4006 0.6455 0.6842 0.2611 0.4439 0.0334 0.8264 0.3676 0.9464 0.3421 0.7249 0.9498 0.5055 0.7406 0.1025 0.8488 0.9069 0.2384 0.5927 0.2580 0.3712 0.0324 0.9530 0.1433 0.9733 0.6781 0.8313 0.5341 0.6430 0.0796 0.9875 0.7814 0.1968 0.2403 0.6053 0.7867 0.8534 0.3764 0.9007 0.9542 0.6534 0.7293 0.3235 0.0373 0.6684 0.7517 0.4440 0.6335 0.5568 0.5792 0.5587 0.0822 0.7003 0.9750 0.5730 0.4409 0.6130 0.3697 0.8086 0.3222 0.5998 0.8630 0.3986 0.1894 0.9762 0.4461 0.8665 0.6238 0.2657 0.8931 0.1609 0.2224 0.7986 0.3995 0.6064 0.5138 0.6179 0.0218 0.8523 0.8333 0.5166 Column 10 0.9724 0.1626 0.2383 0.7039 0.3124 0.3599 0.7378 0.3173 0.5239 0.8691 A(:,:,3) = Columns 1 through 9 0.9264 0.8679 0.0033 0.8766 0.9255 0.3555 0.7942 0.8764 0.2967 0.3775 0.0892 0.1715 0.4714 0.0746 0.9273 0.5639 0.7428 0.1160 0.8253 0.5954 0.9661 0.8789 0.8493 0.6741 0.9836 0.9650 0.1272 0.2577 0.5435 0.7886 0.7708 0.2773 0.6604 0.9164 0.2168 0.8915 0.2344 0.1796 0.8467 0.8431 0.9032 0 0.0178 0.7920 0.1663 0.8168 0.1245 0.9946 0.3664 0.7721 0.9607 0.4229 0.2492 0.8504 0.2022 0.7673 0.2973 0.6931 0.3034 0.5055 0.4239 0.8800 0.8126 0.8488 0.5846 0.7555 0.4614 0.8555 0.6656 0.6729 0.7004 0.8867 0.1395 0.3129 0.5037 0.9812 0.1876 0.5277 0.4847 0.3491 0.6979 0.4650 0.3636 0.7386 0.2566 0.8443 0.6589 0.5487 0.8206 0.6291 Column 10 0.0207 0.1848 0.2488 0.4724 0.3615 0.5011 0.8590 0.2711 0.7776 0.7819 A(:,:,4) = Columns 1 through 9 0.9834 0.0170 0.3327 0.3053 0.4592 0.0648 0.6101 0.4738 0.4911 0.9027 0.0638 0.9934 0.5346 0.9909 0.0644 0.7084 0.1215 0.1305 0.1753 0.1259 0.0672 0.8749 0.4056 0.3597 0.4736 0.9276 0.7412 0.4838 0.3085 0.4793 0.8011 0.8344 0.8962 0.0356 0.3340 0.9667 0.6273 0.8530 0.1107 0.9535 0.1008 0.3188 0.6945 0.7565 0.9664 0.6753 0.3833 0.6893 0.8978 0.7836 0.0127 0.2577 0.0776 0.7353 0.8308 0.3422 0.9401 0.4237 0.6154 0.2810 0.9594 0.4643 0.5750 0.2637 0.4999 0.8809 0.0657 0.7673 0.4607 0.6640 0.9973 0.6489 0.1200 0.0130 0.2139 0.7109 0.1683 0.1035 0.5426 0.9089 0.3218 0.0235 0.9403 0.7842 0.4135 0.6355 0.7067 0.0429 0.7411 0.1188 Column 10 0.9494 0.7868 0.2933 0.9777 0.3123 0.7138 0.8624 0.7224 0.0735 0.3290 A(:,:,5) = Columns 1 through 9 0.0671 0.2316 0.3881 0.0794 0.7339 0.2073 0.2997 0.5081 0.1837 0.3451 0.1053 0.9869 0.3171 0.8882 0.6888 0.8988 0.9412 0.3250 0.6540 0.1977 0.6620 0.7213 0.9440 0.2573 0.5121 0.4667 0.2980 0.3024 0.7256 0.1450 0.9394 0.9858 0.9600 0.0747 0.7683 0.0750 0.4879 0.0705 0.8602 0.3721 0.7366 0.9582 0.8376 0.7981 0.0419 0.4336 0.8659 0.9725 0.0940 0.2985 0.7523 0.9039 0.2212 0.5111 0.0493 0.5032 0.5532 0.0496 0.7415 0.1201 0.3137 0.6366 0.3035 0.9542 0.9413 0.4349 0.9418 0.5025 0.8375 0.8634 0.6700 0.5537 0.4834 0.3832 0.3045 0.3730 0.9899 0.5157 0.0677 0.5683 0.5580 0.1515 0.3110 0.8772 0.9143 0.9951 0.8684 0.3850 0.5601 0.4671 Column 10 0.3876 0.7382 0.0181 0.1487 0.0735 0.3154 0.0361 0.9247 0.8925 0.1825 A(:,:,6) = Columns 1 through 9 0.4394 0.0906 0.6777 0.6357 0.4757 0.3655 0.4550 0.7742 0.7282 0.9947 0.3868 0.4443 0.6047 0.4602 0.4156 0.1175 0.2321 0.1303 0.9027 0.9138 0.8500 0.5406 0.4403 0.6434 0.7167 0.7279 0.8197 0.7534 0.6115 0.3858 0.6600 0.4653 0.3274 0.0509 0.4076 0.9398 0.7772 0.5208 0.2801 0.8052 0.8021 0.9459 0.5634 0.8982 0.7168 0.8719 0.9649 0.4739 0.9661 0.6993 0.7572 0.5048 0.8405 0.9723 0.4664 0.5268 0.6139 0.3553 0.2698 0.0956 0.2533 0.1699 0.4777 0.8460 0.6256 0.1324 0.6529 0.6920 0.2654 0.0590 0.9444 0.6542 0.7161 0.5451 0.6533 0.9136 0.7650 0.6399 0.7489 0.6964 0.4744 0.1753 0.0530 0.6367 0.3819 0.8164 0.0217 0.9010 0.7007 0.3517 Column 10 0.0220 0.8071 0.7712 0.8427 0.0496 0.8208 0.0513 0.9922 0.6773 0.1537 A(:,:,7) = Columns 1 through 9 0.4498 0.6031 0.0750 0.0064 0.5039 0.3841 0.0830 0.2740 0.4767 0.8066 0.9599 0.4264 0.1662 0.7851 0.5384 0.4646 0.6912 0.4123 0.2347 0.6780 0.5113 0.9902 0.0993 0.7036 0.7374 0.8156 0.7632 0.9285 0.0579 0.6518 0.7142 0.4893 0.9569 0.1750 0.8434 0.3803 0.0159 0.9955 0.0013 0.5353 0.2475 0.1151 0.0982 0.8628 0.2090 0.6947 0.2115 0.0881 0.9312 0.0428 0.1992 0.6356 0.4943 0.1477 0.1791 0.6691 0.3983 0.8014 0.2741 0.0500 0.8719 0.3307 0.5247 0.5458 0.5546 0.0078 0.2311 0.1609 0.2282 0.5071 0.0647 0.3427 0.9466 0.5057 0.3535 0.6989 0.3627 0.5261 0.2330 0.1079 0.2804 0.6081 0.7203 0.4631 0.8516 0.7447 0.6676 0.1439 0.8767 0.0010 Column 10 0.4244 0.7887 0.9542 0.4519 0.1113 0.1426 0.3147 0.4172 0.1560 0.1131 A(:,:,8) = Columns 1 through 9 0.4792 0.3879 0.0360 0.2422 0.6220 0.0589 0.1472 0.7461 0.2470 0.4822 0.8051 0.6910 0.6941 0.4868 0.6829 0.0567 0.6161 0.3819 0.3562 0.4779 0.3450 0.7401 0.6823 0.1055 0.8363 0.5113 0.9298 0.3874 0.2016 0.5405 0.2543 0.9035 0.3042 0.8250 0.4804 0.5134 0.1433 0.4672 0.6676 0.4575 0.2805 0.0374 0.2733 0.1470 0.0302 0.9949 0.0126 0.7871 0.5006 0.0176 0.8861 0.5860 0.0199 0.7009 0.1245 0.7015 0.5679 0.6828 0.3241 0.2009 0.9510 0.4661 0.5904 0.7154 0.5380 0.3590 0.1840 0.5566 0.2406 0.3049 0.1296 0.4563 0.6313 0.0018 0.9724 0.2102 0.0904 0.9829 0.1489 0.6609 0.3013 0.8044 0.1309 0.0873 0.5310 0.3096 0.4681 0.1268 0.4199 0.4637 Column 10 0.7380 0.9319 0.6734 0.8169 0.0710 0.6946 0.9869 0.9227 0.7243 0.6104 A(:,:,9) = Columns 1 through 9 0.0501 0.9764 0.3261 0.5341 0.7459 0.8605 0.1063 0.9864 0.3994 0.2640 0.3103 0.6452 0.6319 0.8303 0.0959 0.2986 0.2792 0.5694 0.3743 0.1035 0.5377 0.3884 0.7493 0.9688 0.7403 0.8069 0.7381 0.6377 0.3114 0.6142 0.9302 0.7897 0.0615 0.9106 0.0599 0.9318 0.4313 0.6364 0.6916 0.2273 0.7602 0.8069 0.8960 0.6740 0.7097 0.8339 0.3244 0.6439 0.4358 0.0792 0.8896 0.5261 0.3246 0.7915 0.2302 0.2928 0.2807 0.9074 0.2487 0.1170 0.5209 0.6751 0.7710 0.4709 0.5665 0.3482 0.0459 0.6552 0.6204 0.7373 0.9040 0.2721 0.1276 0.9019 0.8066 0.2107 0.3864 0.7204 0.0330 0.6385 0.4251 0.7207 0.4389 0.7404 0.6741 0.0689 0.2529 0.1711 0.1283 0.1291 Column 10 0.1252 0.3489 0.9007 0.7897 0.4885 0.5748 0.3055 0.3086 0.8272 0.0014 A(:,:,10) = Columns 1 through 9 0.2620 0.6978 0.3076 0.3303 0.1010 0.1643 0.5969 0.3376 0.0302 0.0996 0.1359 0.8070 0.4363 0.3454 0.2465 0.2673 0.1539 0.2696 0.2970 0.7880 0.8983 0.1044 0.4895 0.1007 0.5004 0.2040 0.7361 0.6295 0.1531 0.9434 0.1999 0.2075 0.7135 0.1777 0.0659 0.0601 0.9043 0....

6   Pass
%% test 6 repmat ! 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 = Columns 1 through 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 Column 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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
%% test 7 magic! 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 A = 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
%% test 8 floating (maybe people will work with string recognition) A= 13.3; B = A; assert(isequal(your_fcn_name(A),B))

A = 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!