Create timeseries of a 3d scattered plot
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all,
I have a dataset displayed in a 3D scattered plot superimposed with a closed cylinder.
I wish to plot a time series (movie) showing when each scattered plot point was recorded in the scattered plot.
Below is my interial code:
A = 25*rand(8, 5)
Time = A (:,1) ;
x = A (:,2 ) ;
y = A (:,3 ) ;
z = A (:,4 ) ;
Amplitude = A (:,5) ;
scatter3 (x , y, z, 30, Amplitude);
title ('Sample Material')
xlim ([-50.00 50.00])
ylim ([-50.00 50.00])
zlim ([0.00 100.00])
xlabel ('Breath /m')
ylabel ('Width /m')
zlabel ('Height /m')
pbaspect([1 1 2])
H = colorbar ;
ylabel (H, 'Amplitude')
hold on
r = 25.000;
[X,Y,Z] = cylinder(r);
hsurf = surf (X,Y,Z*100, 'EdgeColor', 'none', 'FaceAlpha', 0.2); % capture the handle of the surf object
patch(X(1,:),Y(1,:),Z(1,:), hsurf.CData(1,:), 'FaceAlpha', 0.2)
patch(X(1,:),Y(1,:),Z(2,:), hsurf.CData(1,:), 'FaceAlpha', 0.2)
My current challenge comes from adding the time series. I will be grateful to have some comments on how to proceed.
Here is my additional code for the timespan:
ts1 = timeseries(A (:,1), x,y,z,Amplitude);
ts1.Name = 'Sample Material - Time Span';
ts1.TimeInfo.Units = 'hours';
ts1.TimeInfo.StartTime = '00.00';
ts1.TimeInfo.Format = 'hh mm, ss';
ts1.Time = ts1.Time - ts1.Time(1);
plot(ts1);
Thank you.
4 commentaires
Simon Chan
le 2 Fév 2022
Modify slightly and let see the following is what you want? You may use this as the starting point.
for k = 1:10
A = 25*rand(8, 5);
Time = A (:,1) ;
x = A (:,2 ) ;
y = A (:,3 ) ;
z = A (:,4 ) ;
Amplitude = A (:,5) ;
scatter3 (x , y, z, 30, Amplitude);
ax = gca;
if k == 1
title ('Sample Material')
xlim ([-50.00 50.00])
ylim ([-50.00 50.00])
zlim ([0.00 100.00])
xlabel ('Breath /m')
ylabel ('Width /m')
zlabel ('Height /m')
pbaspect([1 1 2])
H = colorbar ;
ylabel (H, 'Amplitude')
hold(ax,'on')
r = 25.000;
[X,Y,Z] = cylinder(r);
hsurf = surf (X,Y,Z*100, 'EdgeColor', 'none', 'FaceAlpha', 0.2); % capture the handle of the surf object
patch(X(1,:),Y(1,:),Z(1,:), hsurf.CData(1,:), 'FaceAlpha', 0.2);
patch(X(1,:),Y(1,:),Z(2,:), hsurf.CData(1,:), 'FaceAlpha', 0.2);
else
pause(1);
end
end
Réponse acceptée
Ive J
le 2 Fév 2022
If you want to create an animation (GIF for instance) or a movie (e.g. AVI), you can:
% see: https://mathworks.com/matlabcentral/answers/94495-how-can-i-create-animated-gif-images-in-matlab
for i = 1:20
A = 25*rand(8, 5);
Time = A (:,1) ;
x = A (:,2 ) ;
y = A (:,3 ) ;
z = A (:,4 ) ;
Amplitude = A (:,5) ;
scatter3 (x , y, z, 30, Amplitude);
title ('Sample Material')
xlim ([-50.00 50.00])
ylim ([-50.00 50.00])
zlim ([0.00 100.00])
xlabel ('Breath /m')
ylabel ('Width /m')
zlabel ('Height /m')
pbaspect([1 1 2])
H = colorbar ;
ylabel (H, 'Amplitude')
hold on
r = 25.000;
[X,Y,Z] = cylinder(r);
hsurf = surf (X,Y,Z*100, 'EdgeColor', 'none', 'FaceAlpha', 0.2); % capture the handle of the surf object
patch(X(1,:),Y(1,:),Z(1,:), hsurf.CData(1,:), 'FaceAlpha', 0.2)
patch(X(1,:),Y(1,:),Z(2,:), hsurf.CData(1,:), 'FaceAlpha', 0.2)
hold off
drawnow
frame = getframe(gcf);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1
imwrite(imind, cm, 'myanimation.gif', 'gif', 'Loopcount', 1);
else
imwrite(imind, cm, 'myanimation.gif', 'gif', 'WriteMode', 'append');
end
end
Similarly, for a movie:
for i = 1:20
% plot
drawnow
f(i) = getframe(gcf);
end
vidobj = VideoWriter('mymovie.avi');
vidobj.FrameRate = 10;
open(vidobj);
for i = 1:numel(f); writeVideo(vidobj, f(i)); end
close(vidobj);
8 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Visual Exploration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!