Adding specified loop outputs
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Mathieu NOE
el 2 de Abr. de 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 comentarios
Stephen23
el 9 de Abr. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!