How to stop plotting after function hits first zero in oscillatory system?

1 回表示 (過去 30 日間)
Robert  Flores
Robert Flores 2019 年 5 月 16 日
コメント済み: Robert Flores 2019 年 5 月 16 日
Hello everyone,
I am making a Haversine function, and am wanting the function to stop plotting values after the first zero is hit; this zero occures at haversine50(101). I tried making a for loop, however, it did not do anything. If you can help me resolve this issue by making my plot do one cycle and then be zero for the rest of the time values, it will be greatly appreciated, thank you.
-Robert
CODE:
clc,clear,close all
dt = 1e-4;
time = 0:dt:12e-3;
hz = [50 500 1000];
haversine50 = (0.5)*(1-cosd(hz(1)*2*360*time));
zero = find(haversine50 == 0);
endtime50 = haversine50(zero(2));
for i=1:numel(time)
if haversine50(i) >= endtime50
haversine50(i) = (0.5)*(1-cosd(hz(1)*2*360*time(i)));
elseif (haversine50(i) < endtime50)
haversine50(i) = 0;
end
end
figure(1)
plot(time,haversine50); title('Response'); xlabel('Time, measured in sec'); ylabel('Acceleration, measured in m/s^2')

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 5 月 16 日
clc,clear,close all
dt = 1e-4;
time = 0:dt:12e-3;
hz = [50 500 1000];
haversine50 = (0.5)*(1-cosd(hz(1)*2*360*time));
zero = find(haversine50 == 0);
haversine50(zero(2)+1:end) = 0;
figure(1)
plot(time,haversine50); title('Response'); xlabel('Time, measured in sec'); ylabel('Acceleration, measured in m/s^2')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeClocks and Timers についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by