aggregating profiles of data

1 回表示 (過去 30 日間)
Ashehad Ali
Ashehad Ali 2015 年 6 月 11 日
コメント済み: Ashehad Ali 2015 年 6 月 24 日
Hi there,
I would like to aggregate these three profiles of data-sets (HA01.csv, HA02.csv, HA03.csv) in matlab by determining the means so that the "new data-set" will have the same structure (i.e. the no. of rows and no. of columns as either of the three profiles and that the "new data-set" would contain means for the variables: SW1,SW2,SW3,SW4,SW5,SW6,SW7. That is, in the new-data set, for Hr=0, SW1= mean(x1,x2,x3), where x1 is the SW1 entry in HA01.csv when Hr=0, x2 is the SW1 entry in HA02.csv when Hr=0, where x3 is the SW1 entry in HA03.csv when Hr=0. The unknown values are reported in the data as -9999 or -9998 and when reporting the means, if at least one value is either -9999 or -9998, then the mean can be either -9999 or -9998.
I'm attaching the three data files. Would appreciate your feedback.
Ashehad

採用された回答

Aarti Ghatkesar
Aarti Ghatkesar 2015 年 6 月 16 日
Hi Asheshad
The following code would do the operation of finding the mean for the columns SW1 to SW7 and write to a new file named 'newfile.csv'. Note that 'csvread' or 'dlmread' cannot write column headers.You can use the submission here to write column headers to a csvfile
numofcols=10;
numofrows=25;
ID=csvread('HA01.csv',1,0,[1,0,24,0])
Num=csvread('HA01.csv',1,1,[1,1,24,1])
Hr=csvread('HA01.csv',1,2,[1,2,24,2])
Final=[ID,Num,Hr];
for i=4:1:numofcols
SW_file1=csvread('HA01.csv',1,i-1,[1,i-1,numofrows-1,i-1])
SW_file2=csvread('HA02.csv',1,i-1,[1,i-1,numofrows-1,i-1])
SW_file3=csvread('HA03.csv',1,i-1,[1,i-1,numofrows-1,i-1])
SW=(SW_file1+SW_file2+SW_file3)./3
Final=[Final,SW];
end
csvwrite('newfile.csv',Final,1,0)
Hope it helps
  1 件のコメント
Ashehad Ali
Ashehad Ali 2015 年 6 月 24 日
Hi Aarti,
Thanks for your response.
Best, Ashehad

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

その他の回答 (0 件)

カテゴリ

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