필터 지우기
필터 지우기

Two Subplots in an Animated For-loop Problem

조회 수: 2 (최근 30일)
Stella
Stella 2024년 1월 31일
댓글: Stella 2024년 2월 1일
Hi! I am new to Matlab and trying to learn more each day, and have some issues regarding making both of my subplots play at the same time. For the first plot, I searched for the peaks and valleys and plot them as the data recognized them as peaks/valleys, and have no problem with it. However, the second plot that I want to show is the displacement gathered from the peaks and valleys and show them when the first plot passes through the peaks/valleys. I also don't know how to incorporate the code for it, and I only know to use "comet()" on it but still not what i am looking for. My problem is in the for loop I made. Can you help me? Thanks in advance!
figure(3);
subplot (2,1,1)
h = plot(time(1), mag(1)); hold on; % Start with the first data point
ylabel('Acceleration');
title('Real-time Signal Analysis');
h.XDataSource = 'x1'; % Set the data source properties for dynamic updating
h.YDataSource = 'y1';
for i = 1:200:numel (time)
x1 = time(1:i);
y1 = mag(1:i);
refreshdata(h, 'caller');
drawnow;
[pks, locs] = findpeaks (mag,'MinPeakDistance',1500);
[vks, vlocs] = findpeaks (-mag, 'MinPeakDistance',1300);
vks = -vks;
valid_vks_indices = vlocs (time(vlocs) <= x1 (end));
valid_pks_indices = locs (time(locs) <= x1 (end));
if ~isempty (valid_vks_indices)
plot (time(valid_vks_indices), vks(ismember(vlocs, valid_vks_indices)), 'or');
end
if ~isempty (valid_pks_indices)
plot (time(valid_pks_indices), pks (ismember(locs, valid_pks_indices)), 'or');
end
pause(0.001);
subplot (2,1,2);
xlabel ('Time'); ylabel('Displacement');
for j = i
vel = cumtrapz (time, mag);
vel = filtfilt (b2, a2, vel);
disp = cumtrapz (time, vel);
disp = filtfilt (b2, a2, disp);
plot (time, disp)
end
end
  댓글 수: 4
Angelo Yeo
Angelo Yeo 2024년 2월 1일
Your code doesn't work. Can you check the following lines?
plot (time (vks), mag (ismember 'or')
plot (time, mag, x_pks, y_pks, 'or')
Stella
Stella 2024년 2월 1일
Oh sorry!! This is the updated one.
figure(3);
subplot (2,1,1)
h = plot(time(1), mag(1)); hold on; % Start with the first data point
ylabel('Acceleration');
title('Real-time Signal Analysis');
h.XDataSource = 'x1'; % Set the data source properties for dynamic updating
h.YDataSource = 'y1';
for i = 1:200:numel (time)
x1 = time(1:i);
y1 = mag(1:i);
refreshdata(h, 'caller');
drawnow;
[pks, locs] = findpeaks (mag,'MinPeakDistance',1500);
[vks, vlocs] = findpeaks (-mag, 'MinPeakDistance',1300);
vks = -vks;
valid_vks_indices = vlocs (time(vlocs) <= x1 (end));
valid_pks_indices = locs (time(locs) <= x1 (end));
if ~isempty (valid_vks_indices)
plot (time(valid_vks_indices), vks(ismember(vlocs, valid_vks_indices)), 'or');
end
if ~isempty (valid_pks_indices)
plot (time(valid_pks_indices), pks (ismember(locs, valid_pks_indices)), 'or');
end
pause(0.001);
subplot (2,1,2);
xlabel ('Time'); ylabel('Displacement');
for j = i
vel = cumtrapz (time, mag);
vel = filtfilt (b2, a2, vel);
disp = cumtrapz (time, vel);
disp = filtfilt (b2, a2, disp);
plot (time, disp)
end
end
hold off;

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by