Adding specified loop outputs
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to make a figure which plots the sum of 3 specific loop outputs. output is the different outputs of the loop and I am trying to get the sum of output 1, 2, and 3. This is what I have:
figure
Sum1=sum(output(1:3));
plot(t,Sum1)
But I am just getting a blank graph and Sum1 for some reason has a value of 0 in my workplace. I am not sure which part of what I am doing is incorrect. Thank you for your time!
Réponse acceptée
Mathieu NOE
le 2 Avr 2024
hello again
seems to me you want to sum the first 3 rows so
it should be :
Sum1=sum(output(1:3,:)); instead of Sum1=sum(output(1:3));
output = rand(5,2000)
Sum1=sum(output(1:3,:))
plot(Sum1)
3 commentaires
Stephen23
le 9 Avr 2024
"So this works great until I use any number above 5 as start or finish then I get: Index in position 1 exceeds array bounds. Index must not exceed 5."
Of course you will get that error: if you matrix only has five rows (as with the example give by Mathieu NOE) then what do you expect MATLAB to do when you try to access a non-existent sixth row? Or for that matter, any other row that does not exist.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!