フィルターのクリア

How to sum the values from multiple arrays with the same dimensions?

35 ビュー (過去 30 日間)
Charlotte Findlay
Charlotte Findlay 2018 年 11 月 7 日
コメント済み: Charlotte Findlay 2018 年 11 月 8 日
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?

採用された回答

Guillaume
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
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.
Charlotte Findlay
Charlotte Findlay 2018 年 11 月 8 日
I've actually resolved the problem myself - seems I needed to convert all NaN values to zeroes before I could use your code above. Will accept your above answer! Thanks for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by