フィルターのクリア

Turn function to zero when it reach specific value.

3 ビュー (過去 30 日間)
Abdul Kadir Alhamid
Abdul Kadir Alhamid 2019 年 12 月 22 日
コメント済み: Abdul Kadir Alhamid 2019 年 12 月 22 日
Hello everyone, I am trying to apply sinusoidal force to my structure with a given function, and I want to stop the force whenever it reach the variable "Pu". I try to write this code but it seems doesn't working.Can anyone help me to solve this out?
x = linspace (0,180,1800);
y = 1. * ((exp (-0.01. * x)). * (sin (x)-(x. * cos (x / 2))));
Pu = 30;
for i = 1: length (x)
if x (i)> x (abs (y)> = 30)
y (i) = 0;
end
end
subplot (1,1,1);
axis ([0 180 -50 50]);
grid on
xlabel ( 'Time (min)' )
ylabel ( 'Force (kN)' )
ani1 = animatedline ( 'Color' , 'r' , 'LineStyle' , '-' );
legend ( 'Force Applied' )
for k = 1: length (x)
addpoints (ani1, x (k), y (k));
drawnow
pause (0.01);
end

採用された回答

Vladimir Sovkov
Vladimir Sovkov 2019 年 12 月 22 日
x = linspace (0,180,1800);
y = 1. * ((exp (-0.01 .* x)) .* (sin (x)-(x .* cos (x / 2))));
Pu = 30;
y(find(y>=Pu,1):end)=0;
% for i = 1: length (x)
% if x (i) > x (abs (y) >= 30)
% y (i) = 0;
% end
% end
figure;
subplot (1,1,1);
axis ([0 180 -50 50]);
grid on
xlabel ( 'Time (min)' )
ylabel ( 'Force (kN)' )
ani1 = animatedline ( 'Color' , 'r' , 'LineStyle' , '-' );
legend ( 'Force Applied' )
for k = 1: length (x)
addpoints (ani1, x (k), y (k));
drawnow
pause (0.01);
end
  2 件のコメント
Vladimir Sovkov
Vladimir Sovkov 2019 年 12 月 22 日
If you want to stop when the ABSOLUTE value of y reaches Pu, use y(find(abs(y)>=Pu,1):end)=0;
Abdul Kadir Alhamid
Abdul Kadir Alhamid 2019 年 12 月 22 日
It works! Thanks a lot

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by