Hey guys, I need help in designing a sliding window. In fact, I have a data matrix that it has 82 rows and 600 column, The column related to time. I want to collect the new 82*1 vector in a new sample and add it to my data matrix and remove the first column of the matrix. So, the size of matrix should be the same as before. I don't want to use loops for this issue. Do I have any other way to solve the problem??

 채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 31일

1 개 추천

Simple code:
A = [A(:,2:end), newdata(:)];
Code that might possibly require more computation work but is possibly more efficient in memory:
A(:,1:end-1) = A(:,2:end);
A(:,end) = newdata(:);

추가 답변 (1개)

Wayne King
Wayne King 2011년 10월 31일

0 개 추천

Hi, I'm not certain exactly what you asking for here. It seems to me you want to advance the columns by 1 and replace the first column with the new 82x1 data vector. In what follows, imagine A is your existing data and newdata is the new data vector.
A = randn(82,600);
newdata = randn(82,1);
B = circshift(A,[0 1]);
B(:,1) = newdata;

댓글 수: 2

Walter Roberson
Walter Roberson 2011년 10월 31일
My interpretation is that the first column is shifted out and the new data is put in the last column.
iman102
iman102 2011년 10월 31일
exactly Walter

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

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by