hey all i need to flip every nth column in a matrix. ie. if i have matrix A=[1 2 3;4 5 6;7 8 9] i need it to become A=[1 8 3;4 5 6;7 2 9] any suggestions?

 채택된 답변

Adam
Adam 2014년 10월 20일
편집: Adam 2014년 10월 20일

1 개 추천

n = 2;
colIdx = 2:n:size(A,2);
A(:,colIdx) = flip( A(:,colIdx) )
assuming you want to flip even columns (in the case of n = 2). Obviously for odd colums just change the first line to:
colIdx = 1:n:size(A,2);

추가 답변 (1개)

raja bala
raja bala 2017년 12월 10일

0 개 추천

A(:,[2]) = flip (A(:,[2]))

댓글 수: 1

This flips the 2nd column only, as does
A(:,2) = flip (A(:,2))
without the square brackets.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2014년 10월 20일

댓글:

2017년 12월 11일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by