individual sum of array in cell
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Marc Laub
am 16 Jul. 2020
Beantwortet: Star Strider
am 16 Jul. 2020
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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 16 Jul. 2020
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!