## Mean over specific columns

Antonio Melieni

### Antonio Melieni (view profile)

さんによって質問されました 2019 年 3 月 31 日

### John D'Errico (view profile)

さんによって 編集されました 2019 年 4 月 1 日
Hi :)
I have a 450x42 table.
I would like to calculate the mean over cloumns 2:5 7:10 12:15 and so
mean([2:5],2) mean([7:10],2).....
anybody an idea :)

Walter Roberson

### Walter Roberson (view profile)

2019 年 3 月 31 日
Provided that the pattern keeps up:
squeeze( mean( reshape(Tab{:,setdiff(1:size(Tab,2),1:5:size(Tab,2))}, size(Tab,1), 4, []), 2))
Antonio Melieni

### Antonio Melieni (view profile)

2019 年 3 月 31 日
no idea how to usw that.... can u maybe explain it :)
Walter Roberson

### Walter Roberson (view profile)

2019 年 3 月 31 日
In the above, Tab would be your table object. All of the variables (columns) in the table would have to be numeric for it to work properly. The code I posted could have problems your variables are not all the same numeric type, such as if columns 2:5 were double but columns 7:10 were uint8.

サインイン to comment.

## 1 件の回答

2019 年 3 月 31 日

### John D'Errico (view profile)

2019 年 4 月 1 日

Easy peasy? Convert to an array first of course. Or, if some of those columns are non-numeric, then convert only the indicated columns to an array.
But it is pretty easy to generate that list of columns.
T = rand(450,42);
M = mean(T(:,[2:5]' + (0:5:35)),1);
So the list of column indices is:
ind = reshape([2:5]' + (0:5:35),1,[]);

#### 0 件のコメント

サインイン to comment.

Translated by