Cody

# Problem 10. Determine whether a vector is monotonically increasing

Solution 1802092

Submitted on 1 May 2019 by CHUANQIANG ZHANG
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
x = [0 1 2 3 4]; assert(isequal(mono_increase(x),true));

right = 1 2 3 4 left = 0 1 2 3 temp = 1 1 1 1 output = 1×4 logical array 1 1 1 1 result = logical 1

2   Pass
x = [0]; assert(isequal(mono_increase(x),true));

right = 1×0 empty double row vector left = 1×0 empty double row vector temp = 1×0 empty double row vector output = 1×0 empty logical array result = logical 1

3   Pass
x = [0 0 0 0 0]; assert(isequal(mono_increase(x),false));

right = 0 0 0 0 left = 0 0 0 0 temp = 0 0 0 0 output = 1×4 logical array 0 0 0 0 result = logical 0

4   Pass
x = [0 1 2 3 -4]; assert(isequal(mono_increase(x),false));

right = 1 2 3 -4 left = 0 1 2 3 temp = 1 1 1 -7 output = 1×4 logical array 1 1 1 0 result = logical 0

5   Pass
x = [-3 -4 2 3 4]; assert(isequal(mono_increase(x),false));

right = -4 2 3 4 left = -3 -4 2 3 temp = -1 6 1 1 output = 1×4 logical array 0 1 1 1 result = logical 0

6   Pass
x = 1:.1:10; assert(isequal(mono_increase(x),true));

right = Columns 1 through 18 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 2.8000 Columns 19 through 36 2.9000 3.0000 3.1000 3.2000 3.3000 3.4000 3.5000 3.6000 3.7000 3.8000 3.9000 4.0000 4.1000 4.2000 4.3000 4.4000 4.5000 4.6000 Columns 37 through 54 4.7000 4.8000 4.9000 5.0000 5.1000 5.2000 5.3000 5.4000 5.5000 5.6000 5.7000 5.8000 5.9000 6.0000 6.1000 6.2000 6.3000 6.4000 Columns 55 through 72 6.5000 6.6000 6.7000 6.8000 6.9000 7.0000 7.1000 7.2000 7.3000 7.4000 7.5000 7.6000 7.7000 7.8000 7.9000 8.0000 8.1000 8.2000 Columns 73 through 90 8.3000 8.4000 8.5000 8.6000 8.7000 8.8000 8.9000 9.0000 9.1000 9.2000 9.3000 9.4000 9.5000 9.6000 9.7000 9.8000 9.9000 10.0000 left = Columns 1 through 18 1.0000 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 Columns 19 through 36 2.8000 2.9000 3.0000 3.1000 3.2000 3.3000 3.4000 3.5000 3.6000 3.7000 3.8000 3.9000 4.0000 4.1000 4.2000 4.3000 4.4000 4.5000 Columns 37 through 54 4.6000 4.7000 4.8000 4.9000 5.0000 5.1000 5.2000 5.3000 5.4000 5.5000 5.6000 5.7000 5.8000 5.9000 6.0000 6.1000 6.2000 6.3000 Columns 55 through 72 6.4000 6.5000 6.6000 6.7000 6.8000 6.9000 7.0000 7.1000 7.2000 7.3000 7.4000 7.5000 7.6000 7.7000 7.8000 7.9000 8.0000 8.1000 Columns 73 through 90 8.2000 8.3000 8.4000 8.5000 8.6000 8.7000 8.8000 8.9000 9.0000 9.1000 9.2000 9.3000 9.4000 9.5000 9.6000 9.7000 9.8000 9.9000 temp = Columns 1 through 18 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 Columns 19 through 36 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 Columns 37 through 54 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 Columns 55 through 72 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 Columns 73 through 90 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 output = 1×90 logical array Columns 1 through 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 46 through 90 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 result = logical 1

7   Pass
x = cumsum(rand(1,100)); x(5) = -1; assert(isequal(mono_increase(x),false));

right = Columns 1 through 18 0.9395 1.8534 2.5491 -1.0000 4.4969 4.8983 5.0612 5.2716 5.6666 5.7079 6.1404 6.2067 6.7198 7.4076 7.8580 7.9301 8.4195 9.1018 Columns 19 through 36 9.4688 10.4458 10.4798 11.0383 11.4109 11.9532 12.1300 12.1326 12.6884 13.0421 13.8338 14.6058 14.8193 15.7080 15.9687 16.7771 16.8352 17.2451 Columns 37 through 54 17.3836 18.1975 19.0711 19.6343 19.9314 20.5885 21.5027 22.3815 22.7781 23.5829 23.8048 23.9886 24.2703 24.3514 25.0270 25.6329 26.5224 26.8448 Columns 55 through 72 27.4786 28.3929 29.0110 29.0332 29.7521 30.4038 31.0138 31.1888 31.2985 32.2265 32.8964 33.6089 33.7695 34.6599 35.4723 35.5833 36.1452 36.8733 Columns 73 through 90 37.1104 37.5772 37.7123 38.0760 38.3519 39.0020 39.3585 40.1277 40.3015 41.0288 42.0239 42.8736 43.4064 43.9550 44.7826 45.4206 46.2707 46.4738 Columns 91 through 99 46.8475 47.4481 48.2807 49.1920 49.2059 50.1886 50.1956 50.3197 51.0266 left = Columns 1 through 18 0.1248 0.9395 1.8534 2.5491 -1.0000 4.4969 4.8983 5.0612 5.2716 5.6666 5.7079 6.1404 6.2067 6.7198 7.4076 7.8580 7.9301 8.4195 Columns 19 through 36 9.1018 9.4688 10.4458 10.4798 11.0383 11.4109 11.9532 12.1300 12.1326 12.6884 13.0421 13.8338 14.6058 14.8193 15.7080 15.9687 16.7771 16.8352 Columns 37 through 54 17.2451 17.3836 18.1975 19.0711 19.6343 19.9314 20.5885 21.5027 22.3815 22.7781 23.5829 23.8048 23.9886 24.2703 24.3514 25.0270 25.6329 26.5224 Columns 55 through 72 26.8448 27.4786 28.3929 29.0110 29.0332 29.7521 30.4038 31.0138 31.1888 31.2985 32.2265 32.8964 33.6089 33.7695 34.6599 35.4723 35.5833 36.1452 Columns 73 through 90 36.8733 37.1104 37.5772 37.7123 38.0760 38.3519 39.0020 39.3585 40.1277 40.3015 41.0288 42.0239 42.8736 43.4064 43.9550 44.7826 45.4206 46.2707 Columns 91 through 99 46.4738 46.8475 47.4481 48.2807 49.1920 49.2059 50.1886 50.1956 50.3197 temp = Columns 1 through 18 0.8147 0.9139 0.6957 -3.5491 5.4969 0.4014 0.1629 0.2104 0.3950 0.0413 0.4325 0.0663 0.5131 0.6877 0.4504 0.0721 0.4894 0.6823 Columns 19 through 36 0.3671 0.9770 0.0339 0.5586 0.3725 0.5423 0.1768 0.0026 0.5557 0.3538 0.7916 0.7721 0.2135 0.8887 0.2607 0.8084 0.0580 0.4100 Columns 37 through 54 0.1384 0.8140 0.8736 0.5632 0.2972 0.6571 0.9141 0.8789 0.3966 0.8048 0.2219 0.1838 0.2818 0.0811 0.6756 0.6059 0.8895 0.3224 Columns 55 through 72 0.6337 0.9143 0.6181 0.0222 0.7189 0.6517 0.6100 0.1750 0.1097 0.9280 0.6699 0.7125 0.1606 0.8904 0.8123 0.1110 0.5619 0.7281 Columns 73 through 90 0.2372 0.4668 0.1352 0.3636 0.2759 0.6501 0.3566 0.7692 0.1737 0.7273 0.9951 0.8496 0.5328 0.5486 0.8276 0.6380 0.8501 0.2031 Columns 91 through 99 0.3737 0.6006 0.8326 0.9113 0.0140 0.9827 0.0070 0.1241 0.7070 output = 1×99 logical array Columns 1 through 45 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 46 through 90 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 91 through 99 1 1 1 1 1 1 1 1 1 result = logical 0

8   Pass
x = cumsum(rand(1,50)); assert(isequal(mono_increase(x),true));

right = Columns 1 through 18 0.7079 1.0818 1.1411 1.2794 1.9014 2.0488 2.9806 3.1337 3.2173 3.5668 4.3830 5.1088 6.0609 6.6774 7.1692 7.5883 8.5076 9.3814 Columns 19 through 36 10.3261 11.1829 11.7735 12.4425 12.5110 12.6141 13.3651 14.1490 14.2605 14.4319 15.3351 15.8018 16.0946 16.4743 16.7525 17.0831 17.8563 18.6795 Columns 37 through 49 18.8948 19.8519 20.4767 20.5546 21.1967 21.6797 22.1091 22.1636 22.3779 23.1276 23.8522 23.9413 24.3327 left = Columns 1 through 18 0.6250 0.7079 1.0818 1.1411 1.2794 1.9014 2.0488 2.9806 3.1337 3.2173 3.5668 4.3830 5.1088 6.0609 6.6774 7.1692 7.5883 8.5076 Columns 19 through 36 9.3814 10.3261 11.1829 11.7735 12.4425 12.5110 12.6141 13.3651 14.1490 14.2605 14.4319 15.3351 15.8018 16.0946 16.4743 16.7525 17.0831 17.8563 Columns 37 through 49 18.6795 18.8948 19.8519 20.4767 20.5546 21.1967 21.6797 22.1091 22.1636 22.3779 23.1276 23.8522 23.9413 temp = Columns 1 through 18 0.0829 0.3739 0.0593 0.1384 0.6219 0.1474 0.9318 0.1531 0.0837 0.3495 0.8162 0.7257 0.9522 0.6165 0.4919 0.4191 0.9193 0.8738 Columns 19 through 36 0.9447 0.8568 0.5906 0.6690 0.0685 0.1031 0.7510 0.7839 0.1115 0.1714 0.9032 0.4666 0.2929 0.3797 0.2782 0.3306 0.7732 0.8233 Columns 37 through 49 0.2152 0.9572 0.6248 0.0779 0.6422 0.4830 0.4294 0.0545 0.2143 0.7497 0.7245 0.0891 0.3914 output = 1×49 logical array Columns 1 through 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 46 through 49 1 1 1 1 result = logical 1

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!