Compose two vectors from one vector with step

Hi, I have vector S=[1:64]. I want to compose two vectors:
S_1=[ 1 2 3 4 9 10 11 12 17 18 19 20 ....], step of M=4
S_2=[5 6 7 8 13 14 15 16 21 22 23 24....], step of M=4
L=length(S)
length(S_1)=length(S_2)=L/2

댓글 수: 1

yousef Yousef
yousef Yousef 2022년 12월 9일
이동: Voss 2022년 12월 9일
S = 1:64;
xx = reshape(x, 4, 16);
xxx=xx(:,1:2:end)
xxxx=xx(:,2:2:end-1)
S_1=xxx(:)'
S_2=xxxx(:)'
This answer does what I want. However Im sure there is a way to answer this question in a shorter code, any advice? Thank you

댓글을 달려면 로그인하십시오.

 채택된 답변

Voss
Voss 2022년 12월 9일
편집: Voss 2022년 12월 9일
N = 64;
S = 1:N;
M = 4;
S_new = reshape(permute(reshape(S,M,2,[]),[1 3 2]),N/2,[]).'
S_new = 2×32
1 2 3 4 9 10 11 12 17 18 19 20 25 26 27 28 33 34 35 36 41 42 43 44 49 50 51 52 57 58 5 6 7 8 13 14 15 16 21 22 23 24 29 30 31 32 37 38 39 40 45 46 47 48 53 54 55 56 61 62
Now S_new(1,:) is your S_1 and S_new(2,:) is your S_2.

댓글 수: 5

Perfect. Appreciated it
Thank you
I just have one more question. I'm a modelling transmitter and receiver. This work is needed to be done at the transmitter. I want to have the original signal at the receiver. I mean reconstruct S back. Any idea? Thank you
S_reconstructed = reshape(permute(reshape(S_new.',M,[],2),[1 3 2]),1,[])
Perfect. Appreciated. Thank you
Voss
Voss 2022년 12월 9일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 RF Blockset Models for Transceivers에 대해 자세히 알아보기

태그

질문:

2022년 12월 9일

댓글:

2022년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by