individual sum of array in cell

4 ビュー (過去 30 日間)
Marc Laub
Marc Laub 2020 年 7 月 16 日
回答済み: Star Strider 2020 年 7 月 16 日
Hey,
I have a cell, for example:
array1 = {[4,3.3,2.5,0.71];[3.4,2,1,0.3];...}
and I need the sum of each individual array as in
results=[10.51,6.7,...];
and I was wondering if it is possible to do this witouht looping.
Is that possible or is a loop the only or at least most efficient way?
Best regards

採用された回答

Star Strider
Star Strider 2020 年 7 月 16 日
Use the cellfun function:
array1 = {[4,3.3,2.5,0.71];[3.4,2,1,0.3]};
results = cellfun(@sum, array1)
producing:
results =
10.5100
6.7000
Ther are obviously implicit loops within the function. It avoids the use of explicit loops.
.

その他の回答 (0 件)

カテゴリ

Find more on Loops and Conditional Statements in Help Center and File Exchange

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by