Effacer les filtres
Effacer les filtres

Adding SPMD results - no loop

3 vues (au cours des 30 derniers jours)
Alex Kurek
Alex Kurek le 4 Déc 2015
I have some multiple outputs from SPMD, each containing dofferent part of matrix:
finalImage = cell2mat(finalImageAll(1)) + cell2mat(finalImageAll(2)) + cell2mat(finalImageAll(3));
How can I add them all together in a vectorized way (no loop), in one line or so? In this example I show three, but there will be more of them (up to ~50).

Réponse acceptée

Mohammad Abouali
Mohammad Abouali le 4 Déc 2015
Modifié(e) : Mohammad Abouali le 4 Déc 2015
% Creating random sample data
finalImageAll{1}=rand(3,3);
finalImageAll{2}=rand(3,3);
finalImageAll{3}=rand(3,3);
finalImageAll{4}=rand(3,3);
% now summing them all up in one line and no loop
finalImage = sum(cell2mat(reshape(finalImageAll,1,1,numel(finalImageAll))),3)
And the results: (it is random numbers so you would get something else)
finalImage =
2.9640 2.6123 1.1453
2.6784 1.9987 1.8235
1.9245 2.1087 3.4398

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by