How can I get the several sums by three interval of a matrix in matlab?
Afficher commentaires plus anciens
B=load('a.txt');
for i=1:length(B)
if B(i)<5
what is the next step that I can get the sum of all numbers that smaller than 5?
Réponses (2)
Shashank Prasanna
le 10 Fév 2013
You don't need a loop to do that:
B=load('a.txt');
sum(B(B<5))
Example:
B = [1 2 8 6 4 5 9]
>> sum(B(B<5))
ans =
7
Walter Roberson
le 10 Fév 2013
total = total + B(i)
Do not forget to initialize the total.
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!