フィルターのクリア

Separating a vector into two different vectors

1 回表示 (過去 30 日間)
Light
Light 2019 年 3 月 24 日
コメント済み: Light 2019 年 3 月 24 日
Hello everyone, I need helping with sorting elements within a column vector. Let's say for example I had a column vector consisting of 100 elements but I wanted to separate them into two different vectors. The first vector would have every other 10 elements. So it would have the first 10 elements, skip the next 10, and then have the 10 after into it. The second vector I would want to make would contain every other element that was not sorted into the first one so elements 11-20 and so on. Would appreciate some guidance on where to start. Thank you in advance.
  2 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 24 日
Illustrate with an example.
Light
Light 2019 年 3 月 24 日
編集済み: Light 2019 年 3 月 24 日
Like stated lets say I had some vector x = linspace(1,100,100);.
I would want elements x(1:10), elements x(21:30) and so on in a new vector called A. Then I would want the other elements such as x(11:20), x(31:40) in another vector called B.

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

採用された回答

Stephan
Stephan 2019 年 3 月 24 日
編集済み: Stephan 2019 年 3 月 24 日
your_vector = (1:100)';
A = reshape(your_vector,10,[]);
B1 = reshape(A(:,1:2:end),[],1)
B2 = reshape(A(:,2:2:end),[],1)
  1 件のコメント
Light
Light 2019 年 3 月 24 日
Thank you so much! Didn't know about the reshape command in matlab!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by