Azzera filtri
Azzera filtri

Animating a complicated 3d graph

38 visualizzazioni (ultimi 30 giorni)
Harry il 13 Lug 2020
Modificato: jonas il 13 Lug 2020
I have some complicated data that i would like to visualise via a 3d animation. Here is a picture of the unanimated version of it:
What I'd like to do, is to animate it, so that i can see how the various data points move around, whilst still being able to rotate the graph and look at it from different angles. The barrier is that I am using a number of unusual comands to get this plot and am not sure how to add animation on top of them.
Here is a simplified version of my code:
A = rand(6,5);
%create 3d points to be graphed
startv = [A(:,1),A(:,3),zeros(length(A),1)];
endv = [A(:,2),A(:,5),A(:,4)];
%I want to use the vector endv to determine the colour of the lines/points
%to make the graph clearer; so i am going to create a color vector by
%transforming it
figure;hold on
for k = 1 : size(startv, 1)
'LineWidth', 1, 'Color', colorv(k,:), 'MarkerSize', 1)
[startv(k,3)';endv(k,3)'], '.-',...
'LineWidth', 1, 'Color', colorv(k,:), 'MarkerSize', 1);
What I'd like to be able to do would be to use a larger random matrix at the start A=random(6,10) and then have each frame of the animation move from using A(:,5) to A(:,6) to A(:,7) etc but to keep the original colours - so the user can follow individual moving markers.

Risposte (1)

jonas il 13 Lug 2020
Modificato: jonas il 13 Lug 2020
I just made some changes to your code to show you a different way of getting a similar result. Basically, just update the ydata for each handle in a for-loop, either by looping over the handles or by doing it in one line (what I've done here). I've added another point to your lines to get rid of the stem plot.
n = 6;
A = rand(n,15);
%create 3d points to be graphed
[x,y,z] = deal([A(:,1),A(:,2),A(:,2)],...
%values to update with later
y_new = A(:,6:end);
axis([0,1,0,1,0,1]);hold on
grid on;
box on;
h = plot3(x',y',z', '.-',...
'LineWidth', 1, 'MarkerSize', 10);
%if you want to define custom colors, define n-by-3 matrix "colorv", e.g.
%colorv = rand(n,3);
for i = 1:size(y_new,2)
y_new_c = mat2cell([y(:,1),y_new(:,i),y_new(:,i)],repmat(1,1,n),3);


Scopri di più su Animation in Help Center e File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by