Create timeseries of a 3d scattered plot

4 views (last 30 days)
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)
A = 8×5
13.0818 5.5140 14.0092 14.8775 8.8787 23.6924 1.5850 15.8762 6.1108 21.2250 19.1817 16.4236 10.1666 17.3767 18.8237 0.4604 13.5761 3.5632 13.5605 2.1653 21.7514 1.2951 20.0804 19.2080 18.5357 5.8638 0.6297 13.3577 8.0470 14.8173 13.1569 8.0734 15.7814 14.1187 24.2023 4.2932 3.9761 21.4168 24.2942 15.3522
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 Comments
Greek McCoy
Greek McCoy on 3 Feb 2022
Hello,
Thank you for your reply. I tried this option.
Could you kindly tell me what you mean by I may use this as the starting point?
The code works well for my first line of dataset then subsequently not.
The idea is to present the evolution of the scattered data on the same graph with respect to time.
Time = A (:,1) ; %Time in hours from the dataset
Perhaps, I should draft the question better and submit again?
Thank you

Sign in to comment.

Accepted Answer

Ive J
Ive J on 2 Feb 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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!