How can I store values from loops in a vector?

2 ビュー (過去 30 日間)
Philippe Corner
Philippe Corner 2017 年 1 月 5 日
回答済み: Image Analyst 2017 年 1 月 5 日
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

回答 (3 件)

turquoise_squid
turquoise_squid 2017 年 1 月 5 日
reshape the vector with the command 'reshape' to a n x m matrix and perform the mean on its rows.
  1 件のコメント
Philippe Corner
Philippe Corner 2017 年 1 月 5 日
Thats a good idea, Ill try it out! thanks

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


Steven Lord
Steven Lord 2017 年 1 月 5 日
  3 件のコメント
Philippe Corner
Philippe Corner 2017 年 1 月 5 日
Hey bud, this is the code im using:
if true
% code
end
clear all
[P1,P2,P3,P4] = textread('Octubre207.txt','%f %f %f %f','delimiter',';');
P3(P3 == -999) = 0;
A=reshape(P3,1440,31);
S=sum(A)';
movsum(A,31,3)
And command windows shows: Undefined function or variable 'movsum'. do you know what's the mistake?
Image Analyst
Image Analyst 2017 年 1 月 5 日
It's only in R2016a or later.

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


Image Analyst
Image Analyst 2017 年 1 月 5 日
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.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by