How can I make an 2 simultaneous animated line plots?

14 views (last 30 days)
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!
  2 Comments
Cherie Chao
Cherie Chao on 4 Feb 2021
Real neat and complex animation! Though the code was pretty complex, yet it gave me some ideas as to what might have been the problem.Thank you @KSSV.

Sign in to comment.

Accepted Answer

Cherie Chao
Cherie Chao on 4 Feb 2021
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);

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!