How to permute a row vector based on sepecfic method for permutation?

조회 수: 4 (최근 30일)
Sarah A
Sarah A 2018년 9월 14일
댓글: Sarah A 2018년 9월 15일
Hello, suppose we have the matrix x,y,and z that is 1*28 dimension, I want to permute each one of them in this way:
x= [x(1,14),x(1,1), x(1,2), x(1,3), x(1,4), x(1,5), x(1,6),x(1,7), x(1,8),...
x(1,9), x(1,10), x(1,11), x(1,12), x(1,13), x(1,14),x(1,1), x(1,28), x(1,15),...
x(1,16), x(1,17), x(1,18), x(1,19), x(1,20), x(1,21), x(1,22), x(1,23), x(1,24), ...
x(1,25), x(1,26), x(1,27),x(1,28), x(1,15)];
So how can I do that also for y and z without repeating these lines for them also?
Regards,

채택된 답변

David Goodmanson
David Goodmanson 2018년 9월 14일
편집: David Goodmanson 2018년 9월 14일
Hi Sarah,
Since you have more than 28 elements in the final array I would not call it a permutation of elements, strictly speaking. Be that as it may, it makes sense work on an index.
ind = [14 1:14 1 28 15:28 15] % concatenate
xnew = x(1,ind);
ynew = y(1,ind);
znew = z(1,ind);
Since x,y,and z are row vectors and row 1 is the only possibility, you don't have to use the row index. In this case x(14) is the same as x(1,14). It's preferable to use
xnew = x(ind);
ynew = y(ind);
znew = z(ind);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by