sliding window and keeping as a vector

I have D-1 data of points 1-500 I would like to slide this data to have 20points in each window and be as a vector [123...20, 21...40 ect] I was trying to do it but it is showing a matrix (20x25) I am new to matlab anyone could help me please?

回答 (1 件)

Image Analyst
Image Analyst 2014 年 9 月 9 日

0 投票

How about
array2D = reshape(data, [20,25]);
Is that what you meant and want?

9 件のコメント

Nessa
Nessa 2014 年 9 月 9 日
I would like to divide this 500 points into windows where I have first 20 points then another 20 points...and another (stored as a vectors) that I could make other operation on the data later (like what is an average of each bin of this 20 points, medians )
Sean de Wolski
Sean de Wolski 2014 年 9 月 9 日
So:
median(array2D,2)
Start with something simple, data = 1:6 , and build from there. reshape and transpose (.') will be your friends
Image Analyst
Image Analyst 2014 年 9 月 9 日
Nessa, if you have the Image Processing Toolbox, look at blockproc() which will let you apply some function/operation to a vector or image in "jumps" of 20. I.e. the window slides along in jumps of 20 pixels (or whatever you specify) rather than one element at a time. Though you could also process array2D row by row.
Nessa
Nessa 2014 年 9 月 9 日
編集済み: Image Analyst 2014 年 9 月 9 日
thank you, what I did is reshape(data,20,[]); and that is showing me is a matrix instead of vector :(
and Ive read online that there is a way of sliding windows data into n-samples and keep it as a vector not as a matrix.
Image Analyst
Image Analyst 2014 年 9 月 9 日
Well you said you were starting with a vector, so what's the problem? It's already a vector. What operation do you want to do? Moving average, moving mean, some custom linear filter, some highly customized set of operations you've encapsulated into a custom function? What?
Image Analyst
Image Analyst 2014 年 9 月 9 日
Nessa's "Answer" moved here:
calculate an average from each 20 points and further 20 points up to 500
Image Analyst
Image Analyst 2014 年 9 月 9 日
Try this:
data = randi(9, 1, 500); % Sample data
array2D = reshape(data, [20, 25]);
means = mean(array2D, 1)
Nessa
Nessa 2014 年 9 月 9 日
thank you :)
Image Analyst
Image Analyst 2014 年 9 月 9 日
You're welcome. If we're done, then can you please mark the answer as "Accepted"? Thanks.

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

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

質問済み:

2014 年 9 月 9 日

コメント済み:

2014 年 9 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by