How to loop around cumsum ?

조회 수: 4 (최근 30일)
Lea Enguehard
Lea Enguehard 2020년 6월 3일
댓글: Image Analyst 2020년 6월 4일
Hello,
I have a file 3600x601 and I would like to obtain a file 1x601 where each 601 value in the new file is the cumulative sum of the associated 3600 values.
I have written this:
for i =1:601
Csflux = cumsum(Flux(i,:));
end
where Flux is 3600x601
At the end I have Csflux 1x601 but it's the cumulative sum of each 601, so it's not what I want.
Do you have any ideas?
I am working on a current fluxes in a coral reef :)
  댓글 수: 1
James Tursa
James Tursa 2020년 6월 3일
편집: James Tursa 2020년 6월 3일
Please show a small example. E.g., show a specific 5x3 input and the desired output.

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

답변 (1개)

Image Analyst
Image Analyst 2020년 6월 3일
Did you just want the sum of each column? Like this:
columnSums = sum(Flux, 1);
  댓글 수: 2
Lea Enguehard
Lea Enguehard 2020년 6월 3일
I want the cumulative sum of each 3600 value
Image Analyst
Image Analyst 2020년 6월 4일
Lea, we still don't know what you mean, in spite of James and I asking for more clarification or an example. By the way, is this homework?
Is this what you mean?
% Create small test data set.
Flux = randi(9, 5, 15);
columnSums = sum(Flux, 1);
cSums = zeros(size(Flux)); % Preallocate space.
for column = 1 : size(Flux, 2)
thisCumulativeSum = cumsum(Flux(:, column)) % Let's see it first (optional).
cSums(:, column) = thisCumulativeSum
end
Here each column is the cumulative sum, as you go down the rows, of the original column in Flux.

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

카테고리

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