Turn function to zero when it reach specific value.

조회 수: 14 (최근 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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by