Adding specified loop outputs
2 次查看(过去 30 天)
显示 更早的评论
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!
采纳的回答
Mathieu NOE
2024-4-2
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 个评论
Stephen23
2024-4-9
"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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!