I have 20 files of matrices which all contain the same kind of data. I can import and take the single column I need out of every file into a list. I need to average each of the 20 file's lists together, row by row. However, some lists have better resolution than others, and are 200 elements long while others are 100. I want to automatically take every second element of the 200-element long lists, in order to average them with the 100-element long lists. This should return one single list of 100 numbers which is an average of all the 20 files.
I can sort out the long lists using Select[]. Is there an elegant way to take every second element of the long lists automatically, and then rejoin those now 100-element lists with the original 100-element lists to average them? Maybe a for loop or an if-statement?
A[[;;;;2]]
, a shorter form ofA[[1;;-1;;2]]
. See also the documentation ofSpan
. $\endgroup$0.5 A[[1 ;; ;; 2]] + 0.5 A[[2 ;; ;; 2]]
to average the even and odd entries. $\endgroup$A
is only one of the long lists. $\endgroup$