Combining two or more elements of vectors into 1

2 ビュー (過去 30 日間)
Fahmid Mahmud
Fahmid Mahmud 2022 年 4 月 7 日
編集済み: Stephen23 2022 年 4 月 7 日
***This is for encoding of convolutional code***
I have the following vectors, all of them are 1x7 in size
p = 1 0 0 1 1 1 0
q = 1 1 0 1 0 0 1
r = 1 0 1 0 0 1 1
I want to make the following vector 1x7 in size
z = 111 010 001 110 100 101 011
Each element of z is the 3 bits of p,q,r of the same position as a whole bit. If I am not wrong, this is called multiplexing.
Can anyone help how to do it in MATLAB R2021a?
Thank you.

回答 (2 件)

Davide Masiello
Davide Masiello 2022 年 4 月 7 日
編集済み: Davide Masiello 2022 年 4 月 7 日
The problem I see is that z cannot be an array of doubles, since 010 and 001 would be just 10 and 1 respectively. You could try and store the bits in a cell array.
clear,clc
p = [1 0 0 1 1 1 0];
q = [1 1 0 1 0 0 1];
r = [1 0 1 0 0 1 1];
z = [p;q;r];
z = mat2cell(z',ones(1,size(z,2)),3)'
z = 1×7 cell array
{[1 1 1]} {[0 1 0]} {[0 0 1]} {[1 1 0]} {[1 0 0]} {[1 0 1]} {[0 1 1]}

Stephen23
Stephen23 2022 年 4 月 7 日
編集済み: Stephen23 2022 年 4 月 7 日
In MATLAB binary data is normally stored as character (see BIN2DEC, DEC2BIN, etc.).
Perhaps STRING suits your needs (it gives exactly the size that you request):
p = [1,0,0,1,1,1,0];
q = [1,1,0,1,0,0,1];
r = [1,0,1,0,0,1,1];
s = ""+p+q+r
s = 1×7 string array
"111" "010" "001" "110" "100" "101" "011"

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by