How can I make an 2 simultaneous animated line plots?

14 次查看(过去 30 天)
Thanks to Cris in my previous question here, one animated plot has been successful!
1) I wonder if it is possible to do 2 simultaneous plots from the same table as tiles?
I tried it here, but I seem to have an error message, even after I remove all the appearances settings:
%set(groot,'defaultfigureposition',[0 0 1000 1000])
a1 = animatedline;%('color',[1 1 1]);
axis([0 3 0 1650])
a2 = animatedline;%('color',[1 1 1]); % NEW ADD IN
axis([0 3 0 1650]) % NEW ADD IN
%appearances settings
%title('POL AF7 EEG', 'color',[.5 .5 .5])
%xlabel('Time (s)')
%ylabel('Voltage (uV)')
%set(gcf,'color',[0 0 0])
%set(gca,'color',[0 0 0])
%set(gca,'xcolor',[.5 .5 .5])
%set(gca,'ycolor',[.5 .5 .5])
opts = detectImportOptions("d_museMonitor_2021-01-21--18-36-17.csv");
opts.VariableNamesLine = 1;
T = readtable('d_museMonitor_2021-01-21--18-36-17.csv',opts);
fs=256;
t = ((1:height(T))-1)/fs;
v = VideoWriter('2_channel.mp4','MPEG-4');
open(v);
for k = 1:height(T)
tiledlayout(2,1) % NEW ADD IN
nexttile % NEW ADD IN
addpoints(a1, t(k), T.RAW_AF7(k)) % ERROR LINE
title('AF7') % NEW ADD IN
nexttile % NEW ADD IN
addpoints(a2, t(k), T.RAW_AF8(k))
title('AF8') % NEW ADD IN
frame = getframe(gcf);
writeVideo(v,frame);
% set the xlims to create a scrolling window
xlim([max(0, t(k)-3) max(3, t(k))])
drawnow limitrate
end
close(v);
This is the error message:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in 2_channel (line 33)
addpoints(a1, t(k), T.RAW_AF7(k))
The image I get I will also attach here.
Thanks in advance for your kindest assistance!

采纳的回答

Cherie Chao
Cherie Chao 2021-2-4
Haha, I found this similar question afterwards and edited the code to suit my needs. Welcome anyone who has any more suggestions!
clear all
clc
set(groot,'defaultfigureposition',[0 0 1000 1000]);
opts = detectImportOptions("d_museMonitor_2021-01-21--18-36-17.csv");
opts.VariableNamesLine = 1;
T = readtable('d_museMonitor_2021-01-21--18-36-17.csv',opts);
fs=256;
t = ((1:height(T))-1)/fs;
y1 = T.RAW_AF7;
y2 = T.RAW_AF8;
ymax = max(max(y1, y2));
%VIDEO
v = VideoWriter('EEG.mp4', 'MPEG-4');
open(v);
figure
%appearance settings
set(gcf,'color',[0 0 0]);
for i = 1:(height(T)-1);
%1st graph
subplot(211)
%appearance settings
set(gca,'color',[0 0 0]);
set(gca,'xcolor',[.5 .5 .5]);
set(gca,'ycolor',[.5 .5 .5]);
plot(t(i : i+1), y1(i : i+1), '-w');
axis([0 3 0 ymax]);
%graph label settings
title('AF7','Color',[.5 .5 .5]);
xlabel('Time (s)');
ylabel('Voltage (uV)');
%scrolling window
xlim([max(0, t(i)-3) max(3, t(i))]);
hold on;
%1st graph
subplot(212)
%appearance settings
set(gca,'color',[0 0 0]);
set(gca,'xcolor',[.5 .5 .5]);
set(gca,'ycolor',[.5 .5 .5]);
plot(t(i : i+1), y2(i : i+1), '-w');
axis([0 3 0 ymax]);
%graph label settings
title('AF8','Color',[.5 .5 .5]);
xlabel('Time (s)');
ylabel('Voltage (uV)');
%scrolling window
xlim([max(0, t(i)-3) max(3, t(i))]);
hold on;
%VIDEO
frame = getframe(gcf);
writeVideo(v,frame);
drawnow limitrate nocallbacks;
end
%VIDEO
close(v);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by