How can I get the several sums by three interval of a matrix in matlab?

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?

Respuestas (2)

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

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Feb. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by