Plotting using a for loop in Matlab and finding the highest three consecutive value, given imported spreadsheet table of 1x100 called 'P'?
1 回表示 (過去 30 日間)
古いコメントを表示
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.
回答 (2 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!