Problem 1451. Symmetry of vector
Determine whether the vector is symmetric or not (vector could be even or odd in length).
For example:
x = [1 2 3 3 2 1] is symmetric
x = [1 2 3 4 3 2 1] is symmetric as well!
x = [-1 -2 -3 3 2 1] is not symmetric
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Andriy Nych
on 2 May 2013
Why the vector from "Test Suite" "Test 3" is symmetric?
x = [-1 0 0 1];
y_correct = 1; %% WHY 1?
Ned Gulley
on 2 May 2013
I updated test case #3.
Andrea Corazza
on 20 Jul 2020
Hello everyone,
just a quick hint for this test: at the moment, one can pass this test simply checking whether x(1)==x(end).
However, to me at least, it makes more sense to split the check for even and odd vectors and to check if the corresponding symmetrical elements are the same or not.
If any of the pairs of elements are not equal, then we exit the cycle and we terminate with a false/0.
This is the way I figured out a robust check, otherwise it's just cheating.
KR, Andrea
Solution Comments
Show commentsGroup

Cody Challenge
- 12 Problems
- 465 Finishers
- Add two numbers
- Find the sum of all the numbers of the input vector
- Quote Doubler
- De-dupe
- Cell joiner
- Remove all the words that end with "ain"
- Nearest Numbers
- Find state names that start with the letter N
- Word Counting and Indexing
- Given two arrays, find the maximum overlap
- It dseon't mettar waht oedrr the lrettes in a wrod are.
- Counting in Finnish
Problem Recent Solvers1089
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!