how do i reverse a vector
显示 更早的评论
采纳的回答
更多回答(5 个)
Royi Avital
2011-6-13
This might work as well (For 1D Vectors):
vReversed = v(end:-1:1);
Good luck!
3 个评论
Shweta Kanitkar
2013-5-29
v(end:-1:1) subtracts each element from v(end) by 1.
Walter Roberson
2013-6-28
Matt Eicholtz points out that Shweta's comment is incorrect; no subtraction is done, only indexing.
Cyrus David Pastelero
2020-7-8
This is what I am looking for. Thank you.
Walter Roberson
2011-6-13
2 个投票
fliplr() or flipud()
... But I suspect this is a class assignment. You will need to use your knowledge of MATLAB indexing and looping to work out your assignments for yourself.
v = [1 2 3 4 5];
reversed = flip(v);
disp(reversed);
v = [10, 20, 30, 40, 50];
n = length(v);
for i = 1:n
rev(i) = v(n - i + 1);
end
disp('Reversed vector:');
disp(rev);
1 个评论
Stephen23
18 minutes 前
Doing this in a loop is very inefficient: avoid this approach!
类别
在 帮助中心 和 File Exchange 中查找有关 Neighborhood and Block Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!