Adding specified loop outputs
조회 수: 3 (최근 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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!