Cody

# Problem 6. Select every other element of a vector

Solution 2097939

Submitted on 19 Jan 2020 by kieran Thompson
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 = rand(1,10); actual = everyOther(x); expected = x(1:2:length(x)); assert(isequal(actual, expected))

y = 0.5104 0.5615 0.9501 0.2345 0.8208 0.2185 0.3689 0.5168 0.5777 0.5843 z = 6 y = 0.5104 0.9501 0.2345 0.8208 0.2185 0.3689 0.5168 0.5777 0.5843 y = 0.5104 0.9501 0.8208 0.2185 0.3689 0.5168 0.5777 0.5843 y = 0.5104 0.9501 0.8208 0.3689 0.5168 0.5777 0.5843 y = 0.5104 0.9501 0.8208 0.3689 0.5777 0.5843 y = 0.5104 0.9501 0.8208 0.3689 0.5777

2   Pass
x = rand(1,100); actual = everyOther(x); expected = x(1:2:length(x)); assert(isequal(actual, expected))

y = Columns 1 through 18 0.3017 0.0045 0.4260 0.3093 0.2437 0.4391 0.6827 0.7674 0.3426 0.8414 0.0106 0.6907 0.4459 0.3225 0.7657 0.0002 0.6671 0.2609 Columns 19 through 36 0.7654 0.6486 0.5096 0.8996 0.2615 0.5706 0.7867 0.1073 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 Columns 37 through 54 0.4527 0.6656 0.8398 0.8427 0.8676 0.7756 0.2014 0.5793 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 Columns 55 through 72 0.9869 0.6036 0.4366 0.9017 0.4100 0.8033 0.7093 0.7485 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 Columns 73 through 90 0.8027 0.0211 0.0079 0.3603 0.0431 0.1838 0.4195 0.3003 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 0.9605 0.7902 0.7560 Columns 91 through 100 0.6807 0.1736 0.4893 0.4416 0.9511 0.7612 0.5492 0.1417 0.1317 0.6055 z = 51 y = Columns 1 through 18 0.3017 0.4260 0.3093 0.2437 0.4391 0.6827 0.7674 0.3426 0.8414 0.0106 0.6907 0.4459 0.3225 0.7657 0.0002 0.6671 0.2609 0.7654 Columns 19 through 36 0.6486 0.5096 0.8996 0.2615 0.5706 0.7867 0.1073 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 0.4527 Columns 37 through 54 0.6656 0.8398 0.8427 0.8676 0.7756 0.2014 0.5793 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 0.9869 Columns 55 through 72 0.6036 0.4366 0.9017 0.4100 0.8033 0.7093 0.7485 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 0.8027 Columns 73 through 90 0.0211 0.0079 0.3603 0.0431 0.1838 0.4195 0.3003 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 0.9605 0.7902 0.7560 0.6807 Columns 91 through 99 0.1736 0.4893 0.4416 0.9511 0.7612 0.5492 0.1417 0.1317 0.6055 y = Columns 1 through 18 0.3017 0.4260 0.2437 0.4391 0.6827 0.7674 0.3426 0.8414 0.0106 0.6907 0.4459 0.3225 0.7657 0.0002 0.6671 0.2609 0.7654 0.6486 Columns 19 through 36 0.5096 0.8996 0.2615 0.5706 0.7867 0.1073 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 0.4527 0.6656 Columns 37 through 54 0.8398 0.8427 0.8676 0.7756 0.2014 0.5793 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 0.9869 0.6036 Columns 55 through 72 0.4366 0.9017 0.4100 0.8033 0.7093 0.7485 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 0.8027 0.0211 Columns 73 through 90 0.0079 0.3603 0.0431 0.1838 0.4195 0.3003 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 0.9605 0.7902 0.7560 0.6807 0.1736 Columns 91 through 98 0.4893 0.4416 0.9511 0.7612 0.5492 0.1417 0.1317 0.6055 y = Columns 1 through 18 0.3017 0.4260 0.2437 0.6827 0.7674 0.3426 0.8414 0.0106 0.6907 0.4459 0.3225 0.7657 0.0002 0.6671 0.2609 0.7654 0.6486 0.5096 Columns 19 through 36 0.8996 0.2615 0.5706 0.7867 0.1073 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 0.4527 0.6656 0.8398 Columns 37 through 54 0.8427 0.8676 0.7756 0.2014 0.5793 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 0.9869 0.6036 0.4366 Columns 55 through 72 0.9017 0.4100 0.8033 0.7093 0.7485 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 0.8027 0.0211 0.0079 Columns 73 through 90 0.3603 0.0431 0.1838 0.4195 0.3003 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 0.9605 0.7902 0.7560 0.6807 0.1736 0.4893 Columns 91 through 97 0.4416 0.9511 0.7612 0.5492 0.1417 0.1317 0.6055 y = Columns 1 through 18 0.3017 0.4260 0.2437 0.6827 0.3426 0.8414 0.0106 0.6907 0.4459 0.3225 0.7657 0.0002 0.6671 0.2609 0.7654 0.6486 0.5096 0.8996 Columns 19 through 36 0.2615 0.5706 0.7867 0.1073 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 0.4527 0.6656 0.8398 0.8427 Columns 37 through 54 0.8676 0.7756 0.2014 0.5793 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 0.9869 0.6036 0.4366 0.9017 Columns 55 through 72 0.4100 0.8033 0.7093 0.7485 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 0.8027 0.0211 0.0079 0.3603 Columns 73 through 90 0.0431 0.1838 0.4195 0.3003 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 0.9605 0.7902 0.7560 0.6807 0.1736 0.4893 0.4416 Columns 91 through 96 0.9511 0.7612 0.5492 0.1417 0.1317 0.6055 y = Columns 1 through 18 0.3017 0.4260 0.2437 0.6827 0.3426 0.0106 0.6907 0.4459 0.3225 0.7657 0.0002 0.6671 0.2609 0.7654 0.6486 0.5096 0.8996 0.2615 Columns 19 through 36 0.5706 0.7867 0.1073 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 0.4527 0.6656 0.8398 0.8427 0.8676 Columns 37 through 54 0.7756 0.2014 0.5793 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 0.9869 0.6036 0.4366 0.9017 0.4100 Columns 55 through 72 0.8033 0.7093 0.7485 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 0.8027 0.0211 0.0079 0.3603 0.0431 Columns 73 through 90 0.1838 0.4195 0.3003 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 0.9605 0.7902 0.7560 0.6807 0.1736 0.4893 0.4416 0.9511 Columns 91 through 95 0.7612 0.5492 0.1417 0.1317 0.6055 y = Columns 1 through 18 0.3017 0.4260 0.2437 0.6827 0.3426 0.0106 0.4459 0.3225 0.7657 0.0002 0.6671 0.2609 0.7654 0.6486 0.5096 0.8996 0.2615 0.5706 Columns 19 through 36 0.7867 0.1073 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 0.4527 0.6656 0.8398 0.8427 0.8676 0.7756 Columns 37 through 54 0.2014 0.5793 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 0.9869 0.6036 0.4366 0.9017 0.4100 0.8033 Columns 55 through 72 0.7093 0.7485 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 0.8027 0.0211 0.0079 0.3603 0.0431 0.1838 Columns 73 through 90 0.4195 0.3003 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 0.9605 0.7902 0.7560 0.6807 0.1736 0.4893 0.4416 0.9511 0.7612 Columns 91 through 94 0.5492 0.1417 0.1317 0.6055 y = Columns 1 through 18 0.3017 0.4260 0.2437 0.6827 0.3426 0.0106 0.4459 0.7657 0.0002 0.6671 0.2609 0.7654 0.6486 0.5096 0.8996 0.2615 0.5706 0.7867 Columns 19 through 36 0.1073 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 0.4527 0.6656 0.8398 0.8427 0.8676 0.7756 0.2014 Columns 37 through 54 0.5793 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 0.9869 0.6036 0.4366 0.9017 0.4100 0.8033 0.7093 Columns 55 through 72 0.7485 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 0.8027 0.0211 0.0079 0.3603 0.0431 0.1838 0.4195 Columns 73 through 90 0.3003 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 0.9605 0.7902 0.7560 0.6807 0.1736 0.4893 0.4416 0.9511 0.7612 0.5492 Columns 91 through 93 0.1417 0.1317 0.6055 y = Columns 1 through 18 0.3017 0.4260 0.2437 0.6827 0.3426 0.0106 0.4459 0.7657 0.6671 0.2609 0.7654 0.6486 0.5096 0.8996 0.2615 0.5706 0.7867 0.1073 Columns 19 through 36 0.9013 0.0936 0.2081 0.2757 0.4808 0.4596 0.3600 0.1732 0.1366 0.0021 0.4527 0.6656 0.8398 0.8427 0.8676 0.7756 0.2014 0.5793 Columns 37 through 54 0.7235 0.7573 0.9016 0.7592 0.3097 0.5881 0.9243 0.6405 0.3496 0.7580 0.9869 0.6036 0.4366 0.9017 0.4100 0.8033 0.7093 0.7485 Columns 55 through 72 0.9701 0.9185 0.1660 0.9845 0.3781 0.7712 0.8792 0.9116 0.4147 0.5526 0.8027 0.0211 0.0079 0.3603 0.0431 0.1838 0.4195 0.3003 Columns 73 through 90 0.9442 0.9821 0.8949 0.4841 0.7898 0.3312 0.6180 ...

3   Pass
x = ['A' 'long' 'time' 'ago' 'in' 'a' 'galaxy' 'far' 'far' 'away']; actual = everyOther(x); expected = x(1:2:length(x)); assert(isequal(actual, expected))

y = 'Alongtimeagoinagalaxyfarfaraway' z = 16.5000 y = 'Aongtimeagoinagalaxyfarfaraway' y = 'Aogtimeagoinagalaxyfarfaraway' y = 'Aogimeagoinagalaxyfarfaraway' y = 'Aogieagoinagalaxyfarfaraway' y = 'Aogiegoinagalaxyfarfaraway' y = 'Aogieginagalaxyfarfaraway' y = 'Aogiegiagalaxyfarfaraway' y = 'Aogiegiaalaxyfarfaraway' y = 'Aogiegiaaaxyfarfaraway' y = 'Aogiegiaaayfarfaraway' y = 'Aogiegiaaayarfaraway' y = 'Aogiegiaaayafaraway' y = 'Aogiegiaaayafraway' y = 'Aogiegiaaayafrway' y = 'Aogiegiaaayafrwy'

### Community Treasure Hunt

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

Start Hunting!