repeated condition in a for loop

1 回表示 (過去 30 日間)
m m
m m 2023 年 6 月 1 日
コメント済み: Rik 2023 年 6 月 2 日
N = 50000000;
f = 1E6;
DT = 1E-4;
for L = 1:N
T = DT*double(L); % period
a = 0.1;
b =40*T;
i want to add this condition here:
if 0<t<a*b
A = sin(2*pi*f*t)
elseif a*b<t<b
A = 0;
end
end
thsi condition should be repeated in the loop for each 40*T, knowing that we have 5000 periods

回答 (1 件)

Rik
Rik 2023 年 6 月 1 日

Conditions like 0<t<a*b should be split in Matlab to 0<t && t<a*b.

Note that your code will be overwriting the result and that it relies on undefined variables.

If you want specific suggestions, you will have to explain what you want.

  2 件のコメント
m m
m m 2023 年 6 月 1 日
i want to make a condition on this expression A = sin(2*pi*f*t) (A is an excitation )
this expression should be taken into accound only if the condition 0<t<a*b is verfied, if not A sould be zero.
but i have for loop of time (L iteration for time),
b = 40 T with T is the period defined as T = DT* double(L) , with DT is the time step
my objective is to make the excitation A which is sinisoidal excitaion to a pulsed exciation ( by this condition )
i hope this can help
Rik
Rik 2023 年 6 月 2 日

Where exactly do you want to define t?

If you want to assign 0 to all other values, you can use the condition in the calculation itself:

A = sin(2*pi*f*t)*double(0<t && t<a*b);

This works for a scalar t.

What do you want to do next? How do you want to use the value of A next?

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

カテゴリ

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