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

1 回表示 (過去 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);
  1 件のコメント
Sarah A
Sarah A 2018 年 9 月 15 日
Great! Thank you T.T you are really great thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by