How to flip values greater than zero in a row
조회 수: 1 (최근 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
댓글 수: 1
추가 답변 (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!