iteratively plot in multiple figures with subplots
Mostrar comentarios más antiguos
Hi all,
I want to create 2 figures, each with 2 embedded subplots. Then, I would like to alternatively add points to each of the subplots using an animatedline. I will store figure, ax, and animatedlines in a struct.
First, I created a struct object to contain figure, ax, and animatedline handles. But immediately I realize that something is wrong because the
S = struct;
% create figure objs
S.f1.fig = figure;
S.f2.fig = figure;
for jj = 1:numel(fieldnames(S))
nameFig = strcat('f', num2str(jj));
for kk = 1:2
nameAx = strcat('ax', num2str(kk));
nameAn = strcat('an', num2str(kk));
% select figure jj
fh = findobj( 'Type', 'Figure', 'Number', jj );
fh;
% create ax and animated line
S.(nameFig).(nameAx) = subplot(1,2,kk);
S.(nameFig).(nameAn) = animatedline( S.(nameFig).(nameAx) );
end
end
>> S.f1
ans =
struct with fields:
fig: [1×1 Figure]
ax1: [1×1 Axes]
an1: [1×1 AnimatedLine]
ax2: [1×1 Axes]
an2: [1×1 AnimatedLine]
>> S.f2
ans =
struct with fields:
fig: [1×1 Figure]
ax1: [1×1 Axes]
an1: [1×1 AnimatedLine]
ax2: [1×1 Axes]
an2: [1×1 AnimatedLine]
But immediately I realize that something is wrong because the parent of ax1 is Figure 2, although it should be Figure 1:
>> S.f1.ax1.Parent
ans =
Figure (2) with properties:
Number: 2
Name: ''
Color: [0.9400 0.9400 0.9400]
Position: [476 446 560 420]
Units: 'pixels'
After creating the figure Struct, I would like to plot on the subplots using a loop ( since I am streaming realtime data), for some hypothetical, realtime XNew yNew:
while true
for jj = 1:2
for kk = 1:2
nameFig = strcat('f', num2str(jj));
nameAn = strcat('an', num2str(kk));
addpoints( S.(nameFig).(nameAn), xNew, yNew) % for some hypothetical, realtime XNew yNew
end
end
drawnow;
end
How can I plot iteratively into subplots in different figures? thank you!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Animation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


