I want to average specific sections of a complex text file for data analysis. All files that are to be analysed are the same format so I want to automate the process. I have previously asked a question on this forum but the solution provided only work for the simpler text files I am analysing.
I want to average the data by frequency value, so:
Freq Force etc.5 654 ....5 754 ....5 645 ....10 1029 ....10 1175 ....10 1110 ....15 1354 ....15 1375 ....15 1390 ....
Becomes:
Freq Force etc.5 684 ....10 1105 ....15 1373 ....
My current code, produced with the help of Stephen Cobeldick from a previous question.
fid = fopen('text1.txt','rt');cal = readtable('text1.txt');fclose(fid);tabledata = readtable('text1.txt');tabledata(:,1:4)=[];arraydata = table2array(tabledata);arraydata = sortrows(arraydata);Freq = unique(arraydata(:,1))A = accumarray(Freq,arraydata(:,2:12),[5 15],@mean)
Currently, gives the error 'Second input VAL must be a vector with one element for each row in SUBS, or a scalar.' I have attached the text file being analysed.
Best Answer