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 CenterFile Exchange에서 Statistics 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