This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.
This problem made me think and force me drop my all weapons(predefined function ) even for loop ,and while loop
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.2262 0.5750 0.9668 0.3738 0.9319 0.3006 0.0568 0.5675 0.4777 0.1712
0.9252 0.1298 0.5723 0.8029 0.7453 0.5767 0.6015 0.1751 0.1635 0.5954
0.8066 0.0137 0.5988 0 0.9583 0.1478 0.0142 0.7318 0.5830 0.9965
0.8311 0.6406 0.8894 0.6337 0.2421 0.8019 0.0353 0.3727 0.3974 0.6122
0.0596 0.8800 0.1511 0.0168 0.9632 0.7038 0.6401 0.8960 0.6656 0.3207
0.4265 0.2945 0.7210 0.6083 0.1488 0.2710 0.1210 0.7610 0.2775 0.4370
0.0650 0.1256 0.2667 0.4014 0.4633 0.4344 0.7369 0.4414 0.3523 0.6865
0.6770 0.8447 0.6707 0.7400 0.1498 0.1213 0.4490 0.2105 0.5867 0.5802
0.2803 0.6602 0.4022 0.1721 0.0802 0.1308 0.8118 0.8931 0.6411 0.9860
0.3828 0.5086 0.6814 0.3177 0.5365 0.8186 0.2731 0.2360 0.1673 0.3350
B(:,:,2) =
0.6622 0 0.1948 0.2133 0.4236 0.8937 0.1928 0.9195 0.3294 0.7999
0.5421 0.5158 0.3454 0.9524 0.5844 0.3201 0.1111 0.5685 0.0510 0.2588
0.7418 0.8195 0.5778 0.2552 0.3221 0.6664 0.1793 0.9356 0.4863 0.2423
0.2793 0.6119 0.3253 0.0910 0.0014 0.5632 0.6775 0.0357 0.2724 0.5048
0.7516 0.6664 0.1778 0.6138 0.1149 0.5069 0.3565 0.3476 0.8584 0.8006
0.0652 0.7246 0.1221 0.5347 0.4015 0.2786 0.6580 0.9045 0.4350 0.1677
0.3839 0.1956 0.0498 0.6209 0.0313 0.5597 0.5630 0.0464 0.3523 0.6241
0.5896 0.1237 0.8201 0.0647 0.6568 0.9610 0.6021 0.6974 0.3678 0.1839
0.0013 0.9828 0.4488 0.8170 0.2120 0.8015 0.1818 0.1841 0.7639 0.9702
0.2814 0.3593 0.9352 0.3070 0.2244 0.6577 0.7999 0.2168 0.1396 0.0337
B(:,:,3) =
0.6349 0.6354 0.0265 0.6995 0.1165 0.5408 0.7893 0.3749 0.1768 0.1410
0.6570 0.8566 0.2143 0.2039 0.1267 0.4537 0.2259 0.9690 0.9137 0.5233
0.8832 0.3539 0.3595 0.9013 0.6343 0.4704 0.1791 0.0066 0.0967 0.5927
0.6553 0.2902 0.2492 0.5645 0.2051 0.8961 0.6846 0.6734 0.2256 0.7620
0.3021 0.6979 0.8608 0.2759 0.7481 0 0.9103 0.8184 0.1425 0.6344
0.6558 0.5270 0.7500 0.0905 0.0177 0.2960 0.7414 0.3080 0.7613 0.1622
0.9292 0.3090 0.7211 0.9516 0.3566 0.8576 0.6480 0.0802 0.0293 0.2312
0.3572 0.9555 0.3198 0.6767 0.7482 0.1242 0.5826 0.1853 0.6897 0.3014
0.5857 0.2728 0.5521 0.5573 0.4764 0.7293 0.9756 0.3307 0.5492 0.1022
0.1761 0.7215 0.6224 0.3640 0.1573 0.8104 0.8264 0.3991 0.0892 0.4325
B(:,:,4) =
0.9364 0.4855 0.4437 0.1375 0.8473 0.3772 0.2615 0.7896 0.3792 0.1142
0.7992 0.7443 0.5026 0.6049 0.9808 0.6071 0.2384 0.1129 0.4572 0.7878
0.6287 0.3190 0.1817 0.2733 0.3182 0.0864 0.2178 0.2196 0.4432 0.4138
0.9508 0.3092 0.1811 0.5186 0.9657 0.0537 0.2752 0.9819 0.8350 0.2633
0.5302 0.6302 0.2699 0.1783 0.1630 0.1812 0.5880 0.5325 0.1243 0.9712
0.2185 0.7352 0.2613 0.1533 0.4506 0.2117 0.0143 0.1348 0.7882 0.1108
0.1950 0.4905 0.3088 0.2218 0.9843 0.2471 0.0513 0.9331 0.9632 0.6344
0.9533 0.2349 0.5004 0.1666 0.5490 0.1933 0.2180 0.1386 0.1391 0.8452
0.7324 0.4892 0.6642 0.4537 0.9338 0.9900 0.9557 0.1731 0.3448 0.9355
0.1216 0.1963 0.1293 0.6748 0.3809 0.5694 0.8688 0.7831 0.6712 0.0566
B(:,:,5) =
0.3886 0.7144 0.6239 0.8764 0.5108 0.7983 0.6536 0.5372 0.7001 0.0314
0.2644 0.6440 0.0640 0.7465 0.5120 0.1784 0.9051 0.2325 0.3558 0.5499
0.2131 0.7214 0.4615 0.0111 0.8527 0.7427 0.7338 0.2698 0.1924 0.2523
0.1575 0.1530 0.9265 1.0000 0.0285 0.4305 0.5711 0.9950 0.8884 0.6316
0.7255 0.2675 0.4643 0.9650 0.9763 0.0693 0.9074 0.3871 0.5150 0.9478
0.4769 0.1450 0.1928 0.0409 0.6340 0.1451 0.6208 0.6924 0.1001 0.0147
0.3609 0.3380 0.7281 0.2557 0.0789 0.3427 0.3864 0.9053 0.1661 0.5750
0.5910 0.9434 0.8348 0.3605 0.1172 0.0747 0.7843 0.9674 0.2072 0.2679
0.8852 0.5352 0.7944 0.8572 0.9151 0.2687 0.6496 0.2901 0.7925 0.0239
0.7999 0.2877 0.8973 0.8194 0.7868 0.4743 0.8294 0.0937 0.2955 0.2071
B(:,:,6) =
0.7456 0.1369 0.7719 0.0519 0.2297 0.8527 0.6206 0.3794 0.2653 0.8375
0.2853 0.6465 0.8783 0.7387 0.3459 0.2693 0.4892 0.7763 0.8881 0.7417
0.3645 0.5687 0.9828 0.1404 0.5715 0.6170 0.1896 0.1809 0.2030 0.9322
0.4007 0.0980 0.9531 0.0439 0.6837 0.0038 0.2343 0.1852 0.1632 0.5661
0.1089 0.8909 0.4204 0.3979 0.8500 0.0089 0.6032 0.4210 0.3568 0.7687
0.8325 0.9868 0.2543 0.2756 0.0356 0.6782 0.5986 0.6169 0.7426 0.5115
0.1066 0.5141 0.8018 0.5854 0.3182 0.2093 0.2496 0.0551 0.7136 0.5427
0.9342 0.5593 0.5375 0.1691 0.1446 0.2490 0.2410 0.4454 0.8336 0.4971
0.8568 0.4948 0.6995 0.4041 0.3436 0.0380 0.2595 0.0007 0.1503 0.8349
0.2369 0.6553 0.6711 0.6708 0.2652 0.5697 0.4679 0.0203 0.2629 0.9271
B(:,:,7) =
0.1056 0.0550 0.5449 0.4515 0.3957 0.4731 0.7050 0.3533 0.4375 0.2695
0.4901 0.9816 0.0935 0.1171 0.9019 0.6554 0.5742 0.0143 0.9668 0.2704
0.2516 0.8244 0.9567 0.8270 0.0794 0.5152 0.0665 0.9920 0.1864 0.4210
0.0292 0.9183 0.6264 0.9724 0.9099 0.4709 0.2589 0.7718 0.1125 0.6634
0.3960 0.6489 0.4856 0.4898 0.5369 0.5537 0.8602 0.6709 0.2092 0.6301
0.6623 0.4564 0.7105 0.7463 0.0456 0.6108 0.5200 0.6993 0.1097 0.9981
0.1174 0.1066 0.6659 0.3057 0.7933 0.2395 0.3231 0.5829 0.9437 0.9209
0.3379 0.3128 0.2218 0.2322 0.8305 0.5818 0.4592 0.7339 0.0772 0.5056
0.7400 0.1700 0.2661 0.9437 0.3179 0.6363 0.5595 0.7020 0.2829 0.1264
0.3980 0.7436 0.9204 0.2275 0.2865 0.3185 0.8313 0.1191 0.2739 0.2200
B(:,:,8) =
0.5529 0.8665 0.5493 0.4073 0.6490 0.9143 0.4673 0.4207 0.3180 0.3869
0.4218 0.1633 0.1026 0.4572 0.6493 0.5409 0.8152 0.3768 0.3401 0.6678
0.1523 0.7354 0.7947 0.4397 0.8623 0.2731 0.3111 0.8133 0.5199 0.2658
0.4098 0.4804 0.4006 0.1212 0.4359 0.2624 0.4104 0.5434 0.8403 0.3075
0.5150 0.8711 0.5352 0.3407 0.9446 0.5003 0.5765 0.8520 0.5609 0.4474
0.5735 0.7660 0.9576 0.8494 0.5257 0.2633 0.5978 0.5393 0.7271 0.7854
0.8690 0.9342 0.2004 0.8712 0.1313 0.5848 0.3511 0.8011 0.7461 0.1172
0.7190 0.2965 0.3955 0.6232 0.2771 0.0853 0.3842 0.8915 0.4992 0.0113
0.2619 0.4049 0.0426 0.9176 0.4708 0.9998 0.0941 0.7980 0.8764 0.2391
0.3005 0.3047 0.0986 0.2245 0.3633 0.8500 0.8066 0.2780 0.8308 0.9583
B(:,:,9) =
0.9382 0.6651 0.3289 0.4148 0.5067 0.8532 0.8544 0.2783 0.2001 0.5817
0.0332 0.9199 0.1641 0.4448 0.0888 0.1503 0.4240 0.7390 0.2081 0.3182
0.8602 0.1956 0.5344 0.2849 0.7324 0.0945 0.0727 0.6261 0.3120 0.1163
0.4266 0.7361 0.9965 0.8897 0.2838 0.7083 0.1215 0.6054 0.6384 0.1502
0.0144 0.7493 0.4277 0.5703 0.0220 0.6152 0.3425 0.6256 0.4043 0.9922
0.1460 0.6305 0.3386 0.4651 0.4541 0.8322 0.2022 0.4227 0.5151 0.8379
0.1246 0.0655 0.2640 0.1723 0.3664 0.5686 0.1720 0.0494 0.8203 0.6173
0.0738 0.4542 0.7248 0.6356 0.5142 0.8876 0.2170 0.2909 0.9964 0.4732
0.0906 0.7059 0.9452 0.1478 0.0247 0.1053 0.0822 0.8311 0.4582 0.3470
0.9914 0.4210 0.9641 0.0316 0.7433 0.5904 0.3133 0.3322 0.8826 0.5565
B(:,:,10) =
0.4978 0.1655 0.5453 0.8933 0.0155 0.6650 0.0759 0.9386 0.2597 0.6081
0.8632 0.9227 0.1215 0.6886 0.1037 0.6501 0.4650 0.3779 0.6364 0.7957
0.9531 0.1756 0.0885 0.5166 0.2915 0.3807 0.6904 0.3379 0.4376 0.9864
0.5974 0.6712 0.1805 0.0567 0.6959 0.5277 0.0668 0.2830 0.8628 0.0974
0.0903 0.8608 0.4915 0.4118 0.8492 0.2905 0.3313 0.7387 0.5046 0.8688
0.7177 0.8978 0.9936 0.4086 0.4402 0.4667 0.8241 0.3324 0.6794 0.1888
0.6887 0.7093 0.2044 0.3106 0.6438 0.6170 0.1392 0.4659 0.0542 0.4170
0.7395 0.4879 0.0456 0.0302 0.3696 0.5384 ...
|
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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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
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
|
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!