Turn function to zero when it reach specific value.

13 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Vladimir Sovkov
Vladimir Sovkov am 22 Dez. 2019
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 Kommentare
Vladimir Sovkov
Vladimir Sovkov am 22 Dez. 2019
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 am 22 Dez. 2019
It works! Thanks a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by