How can I store values from loops in a vector?
Show older comments
If I have a column of 50 rows and I want to store in a new vector the sum of first to third row, then second to fourth, etc.. how could be the code? thanks in advance
Answers (3)
turquoise_squid
on 5 Jan 2017
1 vote
reshape the vector with the command 'reshape' to a n x m matrix and perform the mean on its rows.
1 Comment
Philippe Corner
on 5 Jan 2017
Steven Lord
on 5 Jan 2017
1 vote
3 Comments
Philippe Corner
on 5 Jan 2017
Philippe Corner
on 5 Jan 2017
Image Analyst
on 5 Jan 2017
It's only in R2016a or later.
Image Analyst
on 5 Jan 2017
Try conv():
data = rand (50, 1); Sample data.
kernel = [1;1;1]/3; % Kernel to computer the mean of 3.
movingMeans = conv(data, kernel, 'valid') % Mean of 1-3, 2-4, 3-5, etc.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!