필터 지우기
필터 지우기

Sums from different groupings

조회 수: 2 (최근 30일)
rpid
rpid 2019년 1월 28일
댓글: rpid 2019년 1월 28일
Dear all. I have the table below:
n x1 x2 x3 x4 x5 x6 ...
1 20 9 166 124
2 21 8 80 106
3 23 6 94 105
4 25 7 22 90
5 23 9 166 82
6 21 8 100 72
7 24 8 375 82
8 22 9 350 88
9 25 7 84 105
10 21 5 22 90
11 22 9 59 124
12 26 7 51 106
13 23 6 51 105
...
1118
The x1, x2 and x3 columns are collected data. The x4 is a calculus using the x1 and x2 columns.
I need to sum in 3 to 3, 6 to 6, 9 to 9, 12 to 12, 18 to 18, 24 to 24, 48 to 48... the columns x3 and x4 and rearrange the partial sums in the x5, x6, x8... columns.
Results from x5 and x6 need to be referent to 3 to 3; x7 and x8 to 6 to 6 and so on.
How can I solve this?
Thks!

채택된 답변

Rik
Rik 2019년 1월 28일
You can pad a grouping with NaN values and still use a similar idea as your other question:
x=1:17;
N=3;
if mod(numel(x),N)~=0
x((numel(x)+1):N*ceil(numel(x)/N))=NaN;
end
x
squeeze(sum(reshape(x,3,1,[]),'omitnan'))
  댓글 수: 1
rpid
rpid 2019년 1월 28일
Thank you, it helped me a lot! All groupings tested, problem solved.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by