フィルターのクリア

Plotting within for loop

2 ビュー (過去 30 日間)
Sudharsan Srinivasan
Sudharsan Srinivasan 2017 年 7 月 18 日
編集済み: Jan 2017 年 7 月 19 日
Lets say for example I have a variable t = 1:1:5000. I want to execute my "for" loop from 1 to 5000 time steps. Within the "for" loop I have another variable u (which is a single vector value) that changes every time step within the loop. Now I have to plot 't' Vs 'u' within the loop such that the value of u is plotted in the graph for lets say every 50 time steps.
How can I code this?
Thank you

回答 (1 件)

Geoff Hayes
Geoff Hayes 2017 年 7 月 18 日
Sudharsan - does this mean that the first 50 elements of u are plotted against t=1:50, the second 50 elements of u are plotted against t=51:100, etc.? If so, then try
u = zeros(50,1);
k = 1;
for t=1:5000
u(k) = randi(255);
k = k + 1;
if mod(k,50) == 0
plot(t-49:t, u);
k = 1;
end
end
  2 件のコメント
Sudharsan Srinivasan
Sudharsan Srinivasan 2017 年 7 月 19 日
Hello Geoff,
I mean to say that after every 50 time step i want the value of 'u' to be plotted in the graph. u (velocity) is a single vector value that gets updated in my loop for every time step. I wanted to check if the value of 'u' has reached steady state.
And about your code, I did not understand the use of generating random integers.
Jan
Jan 2017 年 7 月 19 日
編集済み: Jan 2017 年 7 月 19 日
@Sudharsan Srinivasan: The random numbers are generated to have some test data for the demonstration. In your code, they are replaced by the original data.
Geoff's code does exactly what you are asking for, except for the check of the steady state, whiich you did not menation in the original question. +1

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by