フィルターのクリア

Defining a for loop

1 回表示 (過去 30 日間)
Sherwin
Sherwin 2012 年 7 月 25 日
Just wondering some of the basics. How to I represent all possibilities of a variable?
I'm trying to say for every time t
How to I put that "for" part into a proper code format?

回答 (2 件)

Wayne King
Wayne King 2012 年 7 月 25 日
編集済み: Wayne King 2012 年 7 月 25 日
It depends on the range of your t variable and how finely you want to represent that.
If 0<=t<=1, then you can't represent it in a computer with an infinite number of values (continuously), but you can do:
t = 0:0.001:1;
represent it in increments of 0.001. Or
t = linspace(0,1,1000);
For example:
t = 0:0.001:1;
x = sin(t);
plot(t,x)
In a "vectorized" language like MATLAB, it is often better to represent things as vectors, or matrices when possible, and then evaluate things over that set, so your "for all t" becomes:
1.) define a vector of t values
2.) evaluate something over for all t in that set

Elizabeth
Elizabeth 2012 年 7 月 25 日
Matlab code
t0= 0; %assign an initial time t0
tf= 100; %set final time tf
for t=t0:tf
{execute commands}
end
Is this all you're asking for?

カテゴリ

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