I attached here 2 text files ..one is input file(complete data of year,month number,Day1 to day31) and second one is output file(year, month wise mean).I want this output format only.

댓글 수: 6

Guillaume
Guillaume 2014년 9월 22일
What is the difficulty you're facing? Looks as simple as averaging column 3 onwards of each row.
skyhunt
skyhunt 2014년 9월 22일
i don't no how to give scripts for loop in this
Geoff Hayes
Geoff Hayes 2014년 9월 22일
Start with importdata to load the data from each file into local variables (structures). The data field of each of these structures will have the numeric data. As some of your columns (for certain rows) are empty, then these will be replaced with NaN.
Then as Guillaume suggested, take the average of each row (only from the input.txt file) from the third column onwards. If you have the Statistics Toolbox, consider using nanmean which will take the average of a set of numbers, ignoring any Nan values. If you don't have this function, then you can write an equivalent version using mean as a guide.
skyhunt
skyhunt 2014년 9월 23일
Thank you replying...
skyhunt
skyhunt 2014년 9월 24일
편집: skyhunt 2014년 9월 24일
I am very new to this matlab. Still i am not getting my format..please anybody help for this script..save my life
Geoff Hayes
Geoff Hayes 2014년 9월 24일
What happened when you loaded the data from file using importdata? Please post some or all of the code that you have written to accomplish this task.

댓글을 달려면 로그인하십시오.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 9월 25일
편집: Andrei Bobrov 2014년 9월 25일

0 개 추천

f=fopen('input.txt');
c = textscan(f,repmat('%f ',1,33),...
'EmptyValue',nan,'HeaderLines',1,'CollectOutput',1);
fclose(f);
c1 = c{1};
val = nanmean(c1(:,3:end),2);
[yrs,~,ii] = unique(c1(:,1));
mmm = cellstr(datestr(datenum(2014,(1:12)',1),'mmm'))';
output = [[{'year'},mmm];
[num2cell(yrs), accumarray([ii, c1(:,2)],val,[],@(x){x})]];

댓글 수: 4

skyhunt
skyhunt 2014년 9월 25일
Thank you for your replying......this is error message ??? Error: File: god.m Line: 7 Column: 7 Expression or statement is incorrect--possibly unbalanced (, {, or [. what i do....?
skyhunt
skyhunt 2014년 9월 25일
편집: skyhunt 2014년 9월 25일
Can I replace the tilde(~) with N variable...and one more question i want ask you? Likewise(above data) I have 100 stations data( 100 .xlsx sheets) and I want to calculate mean every xlsx sheet.Please help me soon..Thanking you very much for your kindly replying.
skyhunt
skyhunt 2014년 9월 26일
I changed tilde with N, now it is working...how to write loop for this about 100 xlsx sheets?..
skyhunt
skyhunt 2014년 9월 27일
I created batch file as 'files.dat', with in that 100 .dat files are there ,and I want create for loop for this above script,please help me..?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2014년 9월 22일

댓글:

2014년 9월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by