Double sum - vector (matrix) solution

3 visualizzazioni (ultimi 30 giorni)
Mikl Nik
Mikl Nik il 30 Nov 2020
Commentato: Mikl Nik il 3 Dic 2020
Hi!
I want to calculate the expression , where C and F - matrix (n x m). How can I do it without loops?
Thank you for your answers!

Risposta accettata

James Tursa
James Tursa il 30 Nov 2020
Modificato: James Tursa il 30 Nov 2020
result = sum(C(:).*F(:));
or for later versions of MATLAB
result = sum(C.*F,'all');
This all assumes that the actual indexing starts at 1, not 0 as your formula above is written, since MATLAB uses 1-based indexing.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by