How to flip only some rows inside a matrix?
조회 수: 3 (최근 30일)
이전 댓글 표시
hey all, if i have vector
A=[2 5 6 7 8 9]
i need it to become a matrix
A=[2 9;
5 8;
7 6]
any suggestions?
댓글 수: 1
the cyclist
2018년 10월 27일
I don't understand the general rule for going from the vector to the matrix. Can you describe it?
채택된 답변
madhan ravi
2018년 10월 27일
A=[2 5 6 7 8 9]
a=fliplr(reshape(A,[3 2]))
a([3 1])= a([1 3])
a=fliplr([a(1:2,:);flip(a(3,:))])
댓글 수: 2
추가 답변 (2개)
Abdul Rehman
2018년 10월 27일
편집: Abdul Rehman
2018년 10월 27일
i have got Answer for you but its not generic for all matrix.you should look for the end and first element of matrix.
Hopefully it's work for you...
if true
A=[2 5 6 7 8 9];
b=(size(A));
[r c]=size(A);
j=1;
gg=c;
for u=c:-1:c-1 %two iteration for size of vector.
if(j==1)
b(j)=A(j); % first value at start
end
if(gg==c)
b(gg)=A(gg/2); %Size of vector divided by 2 center value at end
end
j=j+1;
b(j)=A(u);
b(j+1)=A(j);
j=j+1;
end
b=reshape(b,[2 3])
end
Here Answer:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/192921/image.jpeg)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!