I need help (palindrome vector)

조회 수: 2 (최근 30일)
Cristian
Cristian 2013년 5월 15일
Hello. So I have a vector x=[1 2 3 4 5 6]. I want to create another vector that contains the values of x in that order, followed by the same values in descending order. By using the fliplr function, I obtained this vector y=[x fliplr(x)] -> y=[1 2 3 4 5 6 6 5 4 3 2 1]. The problem is the middle number that repeat itself. I want something like this: y=[1 2 3 4 5 6 5 4 3 2 1]. Can you guys help me?

답변 (2개)

Matt Kindig
Matt Kindig 2013년 5월 15일
y = x([1:end, end-1:-1:1])

Image Analyst
Image Analyst 2013년 5월 15일
Simply don't append the first element of the flipped vector.
flipped = fliplr(x);
y = [x, flipped(2:end)]

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by