4D plots in Matlab?
14 views (last 30 days)
Show older comments
Hi, I was wondering whether one could plot a 4D line graph -- I am trying to track multiple cells in 3D (x, y, z position) over time, with all cells starting at origin (eg. t0(0,0,0), t1(0, 2, 2.5), t2(-1, 3, 4) etc..). This can easily be done in (x,y ,t) in Prism, but I would really like to plot the movement in 3 dimensions over time. Any help would be greatly appreciated!
0 Comments
Answers (2)
Gautam
on 23 Oct 2024 at 10:56
Hello Ali,
If you want to represent the change in 3D position of a graphic over time, you can represent this using with an animation. Here's an example demonstrating this:
numTimePoints = 100;
t = linspace(0, 10, numTimePoints); % Time vector
x = sin(t);
y = cos(t);
z = t;
figure;
hold on;
grid on;
xlabel('X');
ylabel('Y');
zlabel('Z');
view(3);
line = plot3(x(1), y(1), z(1), 'b-', 'LineWidth', 2);
head = plot3(x(1), y(1), z(1), 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r');
% Plot the trajectory as an animation
for i = 1:numTimePoints
line.XData = x(1:i);
line.YData = y(1:i);
line.ZData = z(1:i);
head.XData = x(i);
head.YData = y(i);
head.ZData = z(i);
pause(0.05);
end
This produces the following output:
0 Comments
See Also
Categories
Find more on Annotations 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!