필터 지우기
필터 지우기

Sum a Matrix within a loop...

조회 수: 2 (최근 30일)
duilio fonseca
duilio fonseca 2019년 4월 11일
편집: duilio fonseca 2019년 4월 12일
Hello, i need help with this... i have a loop with massive data, and i have to improve the efficiency of code..
I have to sum a matrix each iteration for that i created an array. Example:
A=ones(10);
B=(1:1:10);
z=10;
for ii=1:z
C=A+B(ii);
end
My solution was:
A=ones(10);
B=(1:1:10);
z=10;
for ii=1:z
C(:,:,ii)=A+B(ii);
end
D=sum(C,3);
But in this point i have a seriously problem with my hardware (i'm using huge timeseries). Do you have any recommendations for solve this? thank you!

채택된 답변

duilio fonseca
duilio fonseca 2019년 4월 11일
I found the solution, is simpler than i thought. I have to set mi variables,
A=ones(10);
B=(1:1:10);
C=0;
z=10;
for ii=1:z
C=C+A+B(ii);
end
that's all.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by