Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I have to sum the mat2d_SRIz matrices that are renewed at each for cycle. I have to make the accumulation of these matrices. If I write: Matrix_sum = matrix_sum + mat2d_SRIz I can't do it. Any solution?

조회 수: 1 (최근 30일)
file=dir('20190710*.mat');
for i=1:length (file)
load(file(i).name)
mat2d_SRIz(mat2d_SRIz<0)=0;
mat2d_SRIz(find(isnan(mat2d_SRIz)==1))=0;
matrice_somma=zeros(360,240);
%matrice_somma=matrice_somma+mat2d_SRIz(1);
end

답변 (1개)

Mahesh Taparia
Mahesh Taparia 2019년 11월 19일
Hi Mario,
As per your code, you have initialized the matrice_somma variable inside the for loop, which is every time assigned to matrix of zeros. At the end of the loop, you might be getting content of last file of mat2d_SRIz variable. So, to overcome this, you can initialize matrice_somma outside the loop as follows:
file=dir('20190710*.mat');
matrice_somma=zeros(360,240);
for i=1:length (file)
load(file(i).name)
mat2d_SRIz(mat2d_SRIz<0)=0;
mat2d_SRIz(find(isnan(mat2d_SRIz)==1))=0;
matrice_somma=matrice_somma+mat2d_SRIz(1); % check with mat2d_SRIz(1), whether is the matrix which you want to add (it depends on your data format).
end
Hope it will help.

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by