フィルターのクリア

how to take an alternating range of elements from a vector to make two new vectors

3 ビュー (過去 30 日間)
Ali Albaidhani
Ali Albaidhani 2022 年 4 月 12 日
コメント済み: Voss 2022 年 4 月 13 日
Hello everyone,
I will try to explain the title with an example.
So let's say i have a vector (a 1x100)
a = [ 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0]
i want to extract only the 1s and the 0s in new vectors. so we will have two 1x50 vectors
a_1=[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
a_0=[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
is there a way to do that in matlab?
regards
Ali

採用された回答

Voss
Voss 2022 年 4 月 12 日
編集済み: Voss 2022 年 4 月 12 日
a = [ 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0];
a_1 = a(a == 1); % elements of a where a equals 1
a_0 = a(a == 0); % elements of a where a equals 0
disp(a_1);
Columns 1 through 37 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 38 through 50 1 1 1 1 1 1 1 1 1 1 1 1 1
disp(a_0);
Columns 1 through 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 38 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0
  4 件のコメント
Ali Albaidhani
Ali Albaidhani 2022 年 4 月 13 日
thank you so much
Voss
Voss 2022 年 4 月 13 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by