How can I append multiple elements to the end of a vector?
7 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Paul
2014-3-5
编辑:Paul
2014-3-5
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)]
this is based on logical indexing, see http://www.mathworks.nl/company/newsletters/articles/matrix-indexing-in-matlab.html
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!