I need help (palindrome vector)
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
Image Analyst
2013-5-15
Simply don't append the first element of the flipped vector.
flipped = fliplr(x);
y = [x, flipped(2:end)]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!