How can I get the several sums by three interval of a matrix in matlab?
Mostrar comentarios más antiguos
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)
Shashank Prasanna
el 10 de Feb. de 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
el 10 de Feb. de 2013
total = total + B(i)
Do not forget to initialize the total.
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!