Writing a closed while loop

I'm trying to write part of a code that continues a function for the time set of 10.
So something like
while t =< 10
delta_R = -10;
Phi2 = beta*(1-((omega_n/omega_d)*exp(-sigma*t).*cos((omega_d*t)-phi)));
Phi2dot = diff(Phi2);
I have values for the terms, just don't know how to write a closed while loop (or closed loop) and I only get things about transfer loops which I'm not looking for.

5 件のコメント

David Hill
David Hill 2021 年 1 月 30 日
What is your question? What are you trying to do? I do not understand your explanation.
David Scidmore
David Scidmore 2021 年 1 月 30 日
Really just looking for the syntax to use a closed loop.
Like while the time of a function is less or equal to ten, a sinsudal force is being acted up on a ball. After the ten seconds it just stops.
Walter Roberson
Walter Roberson 2021 年 1 月 30 日
10 clock time seconds, or 10 CPU seconds, or 10 simulated seconds?
dpb
dpb 2021 年 1 月 30 日
See the examples at
doc while
The first one would seem to match your need with an incrementing operation instead of decrementing.
David Scidmore
David Scidmore 2021 年 1 月 30 日
@Walter Roberson, it would be t increments between 0 to 10. So it would be a function using t as time. So I guess that would be a simulated 10 seconds.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 1 月 30 日

0 投票

t = 0;
while t < 10
some action
t = t + appropriate increment
end
However if the increment is constant then a lot of the time it makes more sense to write a for loop
tvals = linspace(0,10,75); %use appropriate number of divisions
numt = length(tvals) ;
results = zeros(1 numt) ń
for tidx = 1:numt
t = tvals(tidx) ;
someaaction
results(tidx) = value;
end
plot(tvals,results)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2021 年 1 月 30 日

回答済み:

2021 年 1 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by