필터 지우기
필터 지우기

How to covert a 1D vector to 2D matrix with overlapping effectively?

조회 수: 2 (최근 30일)
Kim
Kim 2021년 10월 24일
댓글: Kim 2021년 10월 24일
Dear Experts,
I would like to make a function to covert a 1D vector to a 2D matrix form with overlapping.
==
X = [1, 2, 3, 4, 5 , 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
segment_size = 4; overlap_rate = 0.5
== Expected Results ===
[ 1 3 5 ... 12
2 4 6 ... 13
3 5 7 ... 14
4 6 8 ... 15]
It would be good to use some functions instead of using "for loop".
Thank you

채택된 답변

Matt J
Matt J 2021년 10월 24일
편집: Matt J 2021년 10월 24일
X=randi(30, 1,14);
segment_size = 4;
overlap_rate = 0.5;
d=segment_size*overlap_rate;
idx=(1:segment_size)'+ ( 0:d:(numel(X)-segment_size) );
[~,rec]=unique(idx);
rec=rec(:).';
X,
X = 1×14
9 13 10 9 4 30 12 28 27 20 18 20 12 18
Matrix=X(idx)
Matrix = 4×6
9 10 4 12 27 18 13 9 30 28 20 20 10 4 12 27 18 12 9 30 28 20 20 18
Xrec=Matrix(rec)
Xrec = 1×14
9 13 10 9 4 30 12 28 27 20 18 20 12 18
  댓글 수: 3
Matt J
Matt J 2021년 10월 24일
Thank you for your prompt reply.
You're welcome, but please Accept-click the answer if it fulfills your question.
Then, can you please let me know how to return the 2-D matrix back to a 1-D vector?
I will add it to my Answer.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by