How to sum the values from multiple arrays with the same dimensions?
조회 수: 64 (최근 30일)
이전 댓글 표시
I have four arrays (2400 x 2800) - I need to sum the values of each cell in the first array with the same cell from the other three arrays. How would I go about doing this?
댓글 수: 0
채택된 답변
Guillaume
2018년 11월 7일
Use + ?
result = array1 + array2 + array3 + array4; %of course using the actual names of the arrays
However, it sounds like you shouldn't have 4 separate arrays in the first place, but a 3D array instead:
array3d = cat(3, array1, array2, array3, array4);
in which case,
result = sum(array3d, 3); %sum elements across 3rd dimension
댓글 수: 3
Guillaume
2018년 11월 7일
Well, for us to find what the problem is attach your data as a mat file and show us the code you used.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!