필터 지우기
필터 지우기

Mean over specific columns

조회 수: 9 (최근 30일)
Antonio Melieni
Antonio Melieni 2019년 3월 31일
편집: John D'Errico 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 :)
  댓글 수: 3
Antonio Melieni
Antonio Melieni 2019년 3월 31일
no idea how to usw that.... can u maybe explain it :)
Walter Roberson
Walter Roberson 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.

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

답변 (1개)

John D'Errico
John D'Errico 2019년 3월 31일
편집: John D'Errico 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,[]);

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by