managing two variables in sum function
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Fred
le 10 Fév 2013
Réponse apportée : Steven Lord
le 6 Fév 2020
Hi, I want to manage two variables in a sum function in a way that sum(i*cos(ik)); which i=1:N , k=1:M but I want only want the SUM with respect to i and create a vector which has M values in other way i should be sumed but k only takes a value each time. what can I do? If I should use loops how can I do that? Thanks in advance
0 commentaires
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 6 Fév 2020
Use element-wise operations to create a matrix of data to sum then call sum with a dimension input.
[c, r] = meshgrid(1:5, 1:6);
M = c.^r
sum(M, 1) % Sum down columns
sum(M, 2) % Sum along rows
0 commentaires
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations 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!