Cody

Problem 6. Select every other element of a vector

Solution 1972942

Submitted on 12 Oct 2019 by Sofya Belov
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 y = 0.9327 y = 0.9327 0.6395 y = 0.9327 0.6395 0.3256 y = 0.9327 0.6395 0.3256 0.3922 y = 0.9327 0.6395 0.3256 0.3922 0.0272

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

y = 0 y = 0.5173 y = 0.5173 0.4937 y = 0.5173 0.4937 0.9508 y = 0.5173 0.4937 0.9508 0.5768 y = 0.5173 0.4937 0.9508 0.5768 0.4865 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 y = 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Column 19 0.8807 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 20 0.8807 0.6656 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 21 0.8807 0.6656 0.8563 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 22 0.8807 0.6656 0.8563 0.4059 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 23 0.8807 0.6656 0.8563 0.4059 0.0189 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 24 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 25 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 26 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 27 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 28 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 29 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 30 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 31 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 32 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 33 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 0.9773 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 34 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 0.9773 0.9142 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 35 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 0.9773 0.9142 0.2149 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 36 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 0.9773 0.9142 0.2149 0.6442 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 36 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 0.9773 0.9142 0.2149 0.6442 Column 37 0.1430 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 36 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 0.9773 0.9142 0.2149 0.6442 Columns 37 through 38 0.1430 0.2946 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 36 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 0.9773 0.9142 0.2149 0.6442 Columns 37 through 39 0.1430 0.2946 0.5469 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 36 0.8807 0.6656 0.8563 0.4059 0.0189 0.1577 0.7458 0.1656 0.9264 0.6998 0.8907 0.7608 0.5976 0.6833 0.9773 0.9142 0.2149 0.6442 Columns 37 through 40 0.1430 0.2946 0.5469 0.4269 y = Columns 1 through 18 0.5173 0.4937 0.9508 0.5768 0.4865 0.9507 0.6787 0.4589 0.1890 0.2275 0.9932 0.3503 0.1074 0.2681 0.6661 0.5582 0.1398 0.2570 Columns 19 through 36 0.8807 0.6656 ...

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 = 0 y = 65 y = 65 111 y = 65 111 103 y = 65 111 103 105 y = 65 111 103 105 101 y = 65 111 103 105 101 103 y = 65 111 103 105 101 103 105 y = 65 111 103 105 101 103 105 97 y = 65 111 103 105 101 103 105 97 97 y = 65 111 103 105 101 103 105 97 97 97 y = 65 111 103 105 101 103 105 97 97 97 121 y = 65 111 103 105 101 103 105 97 97 97 121 97 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 119 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 119 121

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!