Hi guys,
I have a 1000*10 cell array, where each cell is a 1*3 3D coordinate. A segment of this cell array is shown below:
The rows represent time in second, and each column represent location of an object, so each cell is an object's coordinate in space at a given second. There are 10 columns for 10 objects, and 1000 rows for 1000 seconds. I wish to create an animation of all these objects' locations in space from 1s to 1000s: how would I do that? The objects can just be scatter points in a MATLAB 3D plot. Thank you for your help!
GZ

 Respuesta aceptada

the cyclist
the cyclist el 24 de Ag. de 2019
% Parameters
NCOORD = 3;
NT = 1000;
NOBJ = 10;
MARKERSIZE = 72;
% Pretend data
C = cell(NT,NOBJ);
C = cellfun(@(x)rand(1,NCOORD),C,'UniformOutput',false);
% Format into numerical array for convenience
coordByTimeByObject = reshape([C{:}],NCOORD,NT,NOBJ);
% Permute for plotting convenience
timeByObjectByCoord = permute(coordByTimeByObject,[2 3 1]);
% Preallocate the movie frames
M(NT).cdata = [];
M(NT).colormap = [];
% Plot each time step
figure
for nt = 1:NT
scatter3(timeByObjectByCoord(nt,:,1),timeByObjectByCoord(nt,:,2),timeByObjectByCoord(nt,:,3),MARKERSIZE,1:NOBJ);
title(sprintf('Time point: %4d',nt))
xlim([0 1])
ylim([0 1])
zlim([0 1])
% Capture the movie frame
M(nt) = getframe(gcf);
clf
end
% Write the video file
v = VideoWriter('Watch the objects move.mp4','MPEG-4');
open(v)
writeVideo(v,M)
close(v)

Más respuestas (2)

Matt J
Matt J el 24 de Ag. de 2019
Points=reshape( [CellArray{:}] ,3,[],10); %
for i=1:1000
X=Points(1,i,:);
Y=Points(2,i,:);
Z=Points(3,i,:);
scatter3(X(:),Y(:),Z(:)); drawnow
end
dpb
dpb el 24 de Ag. de 2019
Dereference the cell array with the curlies "{}"
for i=1:size(CA,2)
scatter3(CA{i}(:,1),CA{i}(:,2),CA{i}(:,3))
if i==1,hold on, end
end
if the cell array is CA the above will put all on a single axis with cycled colors. Insert additional arguments for size or varied color map or whatever--"salt to suit".
Or, could create subplots of additional figure each pass, all just depends on the effect you're after.

Categorías

Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 24 de Ag. de 2019

Respondida:

el 24 de Ag. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by