Set variable = 0 and run while loop

1 回表示 (過去 30 日間)
Raphael Biendarra
Raphael Biendarra 2020 年 10 月 15 日
回答済み: KSSV 2020 年 10 月 15 日
Hi,
I hope you can help me with this problem.
My while loop is running quite good it plots all the results I want.
but I want to run a second loop:
Problem................................................
let
c = 2.5; %random variable
t = 0; %time
I want to plot the output results out of a while loop and once the while loop has finished I want to set c = 0 and run the loop again.
The problem is how can I set c=0, after the loop has finished and how can I plot the results of the second loop together with the results of the first loop in one graph.
  2 件のコメント
Mathieu NOE
Mathieu NOE 2020 年 10 月 15 日
hi
I don't know how you constructed youre code
but I would put the while loop code as a function, that you call from your main script while passing the variables to the function.
Sudhakar Shinde
Sudhakar Shinde 2020 年 10 月 15 日
To plot multiple results on one graph look this: https://www.mathworks.com/help/matlab/ref/hold.html
Plot1
hold on
plot2
hold off

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

回答 (1 件)

KSSV
KSSV 2020 年 10 月 15 日
We can help you in specific if you show us the code.
As of now, you can save the variables inside the loop into an array and plot what you want at the end. You can see the below demo:
X = zeros(5,10) ;
Y = zeros(5,10) ;
count = 0 ;
while count <= 5
count = count+1 ;
X(count,:) = rand(1,10) ;
for i = 1:10
Y(count,i) = rand ;
end
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by