How can I append multiple elements to the end of a vector?

When creating a random vector how can I create a new vector with all of the same elements of the first vector, but with the elements greater than or equal to a certain number appended to the end?
For example
>> A=randi([0 10],1,20)
And then the new vector would have the same elements as A except all of the elements >=6 would be appended to the end of the vector.

 採用された回答

Paul
Paul 2014 年 3 月 5 日
編集済み: Paul 2014 年 3 月 5 日

0 投票

B=[A(A<6), A(A>=6)]
or
ind=(A>=6);
B=[A(~ind), A(ind)]
or if you want to keep the original elements of A and just add the elements that hold your condition:
B=[A, A(A>=6)]

1 件のコメント

Claire
Claire 2014 年 3 月 5 日
Thank you! This is exactly what I was looking for!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNetworks についてさらに検索

タグ

質問済み:

2014 年 3 月 5 日

編集済み:

2014 年 3 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by