Cody

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

Solution 418634

Submitted on 15 Mar 2014 by Abdullah Caliskan
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.3563 0.0516 0.9055 0.1932 0.5721 0.3735 0.3941 0.4637 0.0283 0.4756 0.5041 0.9653 0.6894 0.9494 0.1663 0.3593 0.5898 0.7567 0.6710 0.7684 0.6283 0 0.2564 0.2313 0.0889 0.1872 0.7961 0.9596 0.2830 0.1320 0.1844 0.9899 0.0522 0.3417 0.6113 0.2936 0.0891 0.2254 0.6183 0.0457 0.3498 0.9018 0.5487 0.0519 0.1152 0.7977 0.3313 0.3830 0.8850 0.2085 0.7933 0.4605 0.5757 0.3751 0.5908 0.4533 0.9912 0.8398 0.6658 0.3730 0.6455 0.8423 0.8289 0.9122 0.7374 0.2868 0.1182 0.9733 0.8321 0.5135 0.4997 0.8418 0.1011 0.5099 0.7062 0.4104 0.6227 0.7538 0.8144 0.4390 0.6652 0.2933 0.3825 0.5352 0.1202 0.0635 0.6219 0.0972 0.1491 0.9601 Column 10 0.9431 0.1127 0.6483 0.4808 0.0665 0.8978 0.4972 0.7713 0.0604 0.2625 A(:,:,2) = Columns 1 through 9 0.6511 0 0.6188 0.0551 0.2920 0.8724 0.0239 0.3639 0.6746 0.1336 0.4425 0.4530 0.0984 0.1335 0.6013 0.5749 0.1514 0.8352 0.6385 0.4542 0.0102 0.6498 0.6727 0.3212 0.0465 0.1496 0.6565 0.3849 0.9453 0.5991 0.7641 0.2026 0.2843 0.4225 0.3508 0.9839 0.7657 0.2191 0.6016 0.9880 0.8685 0.4353 0.4677 0.3360 0.9798 0.6529 0.8824 0.6494 0.1253 0.7512 0.9038 0.0226 0.7840 0.2502 0.3815 0.0199 0.3427 0.3645 0.4194 0.9251 0.0651 0.4867 0.6246 0.3000 0.3418 0.4933 0.6762 0.0002 0.5053 0.9240 0.4648 0.7282 0.3401 0.7660 0.7018 0.3758 0.1495 0.6276 0.5341 0.1313 0.4982 0.9189 0.3428 0.8878 0.8635 0.2738 0.7193 0.3668 0.8864 0.8498 Column 10 0.1909 0.1241 0.0028 0.1530 0.5342 0.5106 0.3852 0.3106 0.0036 0.8152 A(:,:,3) = Columns 1 through 9 0.6384 0.2376 0.1660 0.9702 0.0023 0.8868 0.4081 0.7627 0.4328 0.4483 0.8176 0.3260 0.9984 0.6402 0.4206 0.2489 0.8070 0.9043 0.2441 0.4058 0.2964 0.9875 0.8032 0.2838 0.6525 0.6330 0.6302 0.8034 0.4663 0.5583 0.1501 0.2451 0.0482 0.3203 0.7104 0.9830 0.8240 0.9515 0.0675 0.9585 0.0641 0 0.1037 0.6887 0.5852 0.8522 0.9650 0.0690 0.5305 0.2631 0.2392 0.5356 0.3209 0.8406 0.4673 0.7653 0.1668 0.0741 0.1027 0.0293 0.1649 0.5316 0.4688 0.9707 0.5745 0.9474 0.3118 0.4837 0.7023 0.8834 0.8732 0.5452 0.8412 0.9159 0.8111 0.8952 0.4189 0.0076 0.6665 0.0545 0.1791 0.0785 0.4954 0.7105 0.8348 0.3813 0.6109 0.8477 0.5004 0.6345 Column 10 0.9630 0.5340 0.4796 0.7937 0.0927 0.8808 0.0039 0.5115 0.6785 0.5657 A(:,:,4) = Columns 1 through 9 0.4785 0.6888 0.0164 0.3684 0.3412 0.1805 0.4305 0.2100 0.6649 0.3205 0.1474 0.1147 0.0078 0.8391 0.6785 0.4162 0.1309 0.7922 0.6016 0.7776 0.0124 0.6027 0.9825 0.0557 0.7288 0.5205 0.3335 0.9132 0.3991 0.2162 0.4789 0.6265 0.0341 0.4065 0.9055 0.6927 0.6825 0.8983 0.0114 0.3081 0.1813 0.2865 0.9518 0.4025 0.2038 0.9467 0.3070 0.6424 0.7444 0.1230 0.0774 0.9120 0.2158 0.9587 0.0991 0.0611 0.5170 0.8393 0.5800 0.9006 0.9514 0.0787 0.7118 0.5110 0.2195 0.2455 0.2624 0.3285 0.8466 0.3460 0.9331 0.1669 0.1101 0.0828 0.1937 0.5142 0.2682 0.3957 0.2902 0.6029 0.4428 0.5453 0.9504 0.0909 0.4468 0.5502 0.1692 0.8867 0.3775 0.6330 Column 10 0.9300 0.5293 0.6265 0.6808 0.9232 0.1528 0.4057 0.3125 0.6939 0.8907 A(:,:,5) = Columns 1 through 9 0.4907 0.7676 0.8270 0.0335 0.4189 0.6310 0.8782 0.7926 0.6723 0.8058 0.2161 0.2590 0.4060 0.1271 0.3164 0.9024 0.7827 0.8561 0.3264 0.0341 0.0459 0.7163 0.6546 0.9591 0.1522 0.5324 0.4984 0.5499 0.4366 0.2465 0.9213 0.8640 0.4987 0.1926 0.2534 0.0488 0.3888 0.9369 0.6607 0.9840 0.2746 0.7386 0.7910 0.0710 0.3138 0.8968 0.2621 0.3294 0.9834 0.8402 0.0128 0.0607 0.6258 0.6416 0.6761 0.5697 0.6595 0.8963 0.0708 0.6054 0.3898 0.0247 0.7864 0.8284 0.3596 0.0130 0.8657 0.3788 0.5765 0.3000 0.0620 0.2892 0.1101 0.0268 0.7181 0.8010 0.2682 0.8074 0.7342 0.1296 0.4979 0.2792 0.5004 0.3911 0.5550 0.1529 0.6550 0.1042 0.4506 0.8184 Column 10 0.5951 0.5364 0.3309 0.4117 0.7940 0.3432 0.4626 0.3678 0.6796 0.5678 A(:,:,6) = Columns 1 through 9 0.6518 0.7566 0.7264 0.0047 0.7834 0.0262 0.9433 0.7535 0.5505 0.4911 0.8433 0.1480 0.6500 0.6239 0.1552 0.2898 0.8360 0.4274 0.3985 0.7702 0.1479 0.6785 0.8254 0.8339 0.3766 0.2537 0.1524 0.4775 0.9787 0.7048 0.2536 0.0350 0.1949 0.1138 0.5344 0.2475 0.0666 0.1114 0.3810 0.8432 0.4055 0.8298 0.9649 0.4352 0.4474 0.4110 0.3961 0.0764 0.2940 0.2497 0.3381 0.4325 0.1577 0.5328 0.9691 0.4921 0.4108 0.0269 0.4809 0.6711 0.0846 0.6005 0.3547 0.7807 0.2581 0.1430 0.0933 0.8808 0.0524 0.7167 0.9375 0.7731 0.7290 0.0370 0.7989 0.7979 0.2807 0.7343 0.5068 0.1078 0.8817 0.7657 0.9744 0.9302 0.7114 0.5991 0.4995 0.3281 0.9000 0.7341 Column 10 0.4064 0.6042 0.6411 0.1275 0.4962 0.3105 0.5786 0.9436 0.4269 0.0331 A(:,:,7) = Columns 1 through 9 0.9294 0.9429 0.5757 0.4439 0.8845 0.8806 0.1571 0.1524 0.7814 0.9250 0.0966 0.6319 0.0904 0.2550 0.2351 0.6252 0.2308 0.1355 0.3583 0.8459 0.2782 0.7444 0.9090 0.2449 0.6990 0.6580 0.9021 0.2600 0.9094 0.8398 0.0326 0.8946 0.6409 0.0859 0.5629 0.2896 0.7869 0.0113 0.4268 0.4297 0.3985 0.3045 0.5312 0.2918 0.4996 0.5116 0.5237 0.6316 0.0373 0.6250 0.8256 0.8886 0.6223 0.7836 0.5625 0.6503 0.8335 0.9758 0.5676 0.8837 0.2637 0.7159 0.6771 0.6848 0.3851 0.2702 0.5223 0.8945 0.9454 0.2348 0.2807 0.1498 0.0924 0.6493 0.4008 0.9096 0.2142 0.3908 0.8397 0.4123 0.6966 0.8726 0.7629 0.5543 0.3832 0.0039 0.8013 0.4955 0.3622 0.1290 Column 10 0.9459 0.8864 0.5150 0.6794 0.9768 0.1255 0.7522 0.8271 0.7814 0.1909 A(:,:,8) = Columns 1 through 9 0.4286 0.8991 0.0281 0.3001 0.0141 0.5548 0.0091 0.7460 0.9695 0.0145 0.5448 0.9554 0.0734 0.4704 0.8793 0.5965 0.8098 0.1838 0.3253 0.9011 0.6803 0.7674 0.8863 0.5579 0.6090 0.7452 0.2999 0.1347 0.0518 0.8606 0.0850 0.1140 0.7523 0.9189 0.3371 0.4112 0.4505 0.8086 0.9391 0.7288 0.4425 0.8949 0.7336 0.5843 0.2365 0.5723 0.3349 0.6802 0.4479 0.6595 0.8418 0.3011 0.4690 0.1951 0.7920 0.2287 0.9174 0.6512 0.2948 0.1309 0.4956 0.0873 0.7054 0.4197 0.8224 0.2567 0.1695 0.9504 0.1892 0.2582 0.8287 0.1805 0.5325 0.3482 0.8856 0.5314 0.6943 0.1536 0.7329 0.6859 0.5223 0.9257 0.1655 0.9200 0.6338 0.2068 0.0289 0.1168 0.2673 0.2962 Column 10 0.4628 0.9252 0.2159 0.0010 0.9066 0.6800 0.5150 0.5221 0.1029 0.9969 A(:,:,9) = Columns 1 through 9 0.3590 0.3163 0.3984 0.4904 0.1628 0.1582 0.8184 0.2496 0.0654 0.6252 0.7834 0.6705 0.0887 0.9705 0.0621 0.9382 0.3871 0.6104 0.3934 0.9724 0.4405 0.2509 0.5970 0.7018 0.0003 0.4210 0.7016 0.0077 0.5865 0.1329 0.4476 0.2402 0.0865 0.6404 0.6401 0.1116 0.5453 0.7780 0.4392 0.6380 0.0703 0.6168 0.0074 0.7876 0.0958 0.5091 0.7277 0.5476 0.7094 0.3000 0.1738 0.1064 0.2700 0.5978 0.2468 0.6510 0.3951 0.9926 0.8135 0.6514 0.1068 0.8440 0.8122 0.0454 0.6646 0.3983 0.9322 0.0767 0.4987 0.3671 0.7405 0.8146 0.8417 0.9388 0.7513 0.0922 0.3545 0.2845 0.2396 0.8261 0.0894 0.0482 0.5351 0.5224 0.9535 0.1320 0.8306 0.3461 0.1822 0.7313 Column 10 0.9039 0.4522 0.0707 0.2413 0.7319 0.0405 0.4245 0.5402 0.9538 0.2089 A(:,:,10) = Columns 1 through 9 0.1163 0.9151 0.0848 0.3242 0.3130 0.3839 0.5921 0.5569 0.9505 0.6462 0.9010 0.2981 0.6690 0.0764 0.6507 0.3253 0.2739 0.5321 0.1084 0.2142 0.9171 0.2963 0.7914 0.8174 0.9890 0.1321 0.2477 0.9835 0.5471 0.4705 0.9300 0.3654 0.7663 0.1232 0.6997 0.4373 0.2483 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 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0 0 0 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!