How to flip values greater than zero in a row
2 次查看(过去 30 天)
显示 更早的评论
If I have a row in matrix like that
0 0 0 0 1 2 3 0 0 0
I want to make it like that
0 0 0 0 0 0 3 2 1 0
If it is possible to do?
1 个评论
Stephen23
2018-4-16
@Tanmoyee Bhattacharya: the numbers a not only flipped L-R, but have been translated too. How is the new position determined?
采纳的回答
Birdman
2018-4-16
Try this:
A=[0 0 0 0 1 2 3 0 0 0] idx=find(A~=0); A(idx+nnz(A)-1)=fliplr(A(idx)); A(idx(1:end-1))=0
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!