matrices, collect, rows, columns
조회 수: 5 (최근 30일)
이전 댓글 표시
hi every one
I need help with a program to calculate the sum of matrices
If I have a main matrix A and another matrix B and I need to add A+ B = C, then if all of the elements of C are positive, re-combine C+ B and so on, stop when we get a result that is a matrix containing negative elements. finally, we collect all matrices with positive elements.
Regards
댓글 수: 2
James Tursa
2020년 11월 10일
What have you done so far? What specific problems are you having with your code?
How do you want to handle potential infinite looping? How do you want your matrices "collected" at the end of the process? Can you provide a small example?
채택된 답변
David Hill
2020년 11월 10일
C(:,:,1)=A+B;
c=2;
while nnz(C(:,:,end)>0)==numel(C(:,:,end))
C(:,:,c)=C(:,:,c-1)+B;
c=c+1;
end
C=C(:,:,1:end-1);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!