Plotting using a for loop in Matlab and finding the highest three consecutive value, given imported spreadsheet table of 1x100 called 'P'?
이전 댓글 표시
for n = 1:100
PP = P(n,1);
x = n;
plot(x, P);
hold on
end
The code above doesn't work. Please help fix it and make sure to display three consecutive values that have the largest sum.
댓글 수: 1
darova
2021년 3월 31일
I don't you are summing anything
답변 (2개)
P = randn(1,8);
display(P);
Npts = 3;
[~,idx] = max(movsum(P,Npts,'EndPoints','discard'));
display(P(idx+(0:Npts-1)));
Dongyue
2022년 11월 22일
Hi, the followed code could be easier to understand:
P = rand(100,1);
mx = -Inf;
for i = 1:98
mx = max(mx, sum(P(i:i+2)));
end
mx
카테고리
도움말 센터 및 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!