フィルターのクリア

hi, I have 2 columns data, In that every 1 column data of 1000 value (like 1.2345). i have split this data into (1 to 30), (1 to 60),so on (1 to 990).

1 回表示 (過去 30 日間)
manually it is very difficult to do it. and also find the average of that, means avg of (1 to 30), avg of (1 to 60) so on for statistical problem.please any one help me to solve using matlab.

採用された回答

Jos (10584)
Jos (10584) 2018 年 6 月 25 日
Here is a way:
data = randi(10,20,1) % some data (20 points, rather than 1000, so easy to check)
n = 4:4:numel(data) % split from 1 to 4, from 1 to 8 etc (rather than 1:30, 1:60)
M = arrayfun(@(k) mean(data(1:k)), n) % engine
  2 件のコメント
shrisha tv
shrisha tv 2018 年 6 月 25 日
thank you, but I have data, for larger data it will show error.
Jos (10584)
Jos (10584) 2018 年 6 月 25 日
for a N-by-K array
cellM = arrayfun(@(k) mean(data(1:k,:),2), n, 'un', 0) % engine
M = cat(1,cellM{:})

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

その他の回答 (1 件)

Ankita Bansal
Ankita Bansal 2018 年 6 月 25 日
Hi, are you getting error or incorrect answer?
data(2,2) is equivalent to data(1002).
So if you write
n = 30:30:numel(data)
M = arrayfun(@(k) mean(data(1:k)), n)
it will actually calculate avg of (1 to 30), (1 to 60), ... ,(1 to 990), (1 to 1020) and so on. I am assuming that you want to calculate average of (1 to 30), (1 to 60), and so on till (1 to 990) for each column separately.
Which you can do as
data = randi(10,1000,2);
[s_R,s_C]=size(data);
n = 30:30:s_R;
for i=1:s_C
data1=data(:,i) ;
M(:,i) = arrayfun(@(k) mean(data1(1:k)), n)';
end

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by