フィルターのクリア

How to do average of different arrays of a matrix?

2 ビュー (過去 30 日間)
AS
AS 2020 年 1 月 8 日
コメント済み: AS 2020 年 1 月 8 日
I have a matrix having dimension 3490 by 63 and I want make it 698 by 63 by taking average of five data points of different row in a column. For single column my code is working but I want do the same for rest of 62 columns. please help me on this.
clc;clear all;close all;
load data1.dat;
X=data1;
X1=X(:,1)
n=1;
m=5;
sum=[ ] ;
fid1=fopen('smthdata1.dat','w');
for i=1:698;
sum=0;
for j1=n:m
sum=sum+X1(j1);
end
ad_n=(sum./5);
fprintf(fid1,'%d \n',ad_n);
n=m+1;
m=m+5;
i=i+1;
end
fclose(fid1);
  2 件のコメント
Stephen23
Stephen23 2020 年 1 月 8 日
You don't need a loop, just reshape and mean.
AS
AS 2020 年 1 月 8 日
not working reshape and mean..

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

採用された回答

Hiro Yoshino
Hiro Yoshino 2020 年 1 月 8 日
編集済み: Hiro Yoshino 2020 年 1 月 8 日
Try this:
% X --> 3490 x 63 matrix
X = reshape(X, 5, 63, 698);
X = mean(X);
X = reshape(X, 698, 63);
  1 件のコメント
AS
AS 2020 年 1 月 8 日
Thank you so much. Now it is working.

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

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 1 月 8 日
編集済み: KALYAN ACHARJYA 2020 年 1 月 8 日
Yes, Stephen is rightly said, other options, array function or you can use this custom function for Block-wise Operations (5,1)
mat_data=rand(3490,63);
result=sepblockfun(mat_data,[5,1],'mean');
  1 件のコメント
AS
AS 2020 年 1 月 8 日
thank you.

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

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by