# Seeking an efficient method for using 'scatter3' to create a 3D scatter plot of fixed receiver positions.

36 Ansichten (letzte 30 Tage)
Peter Beringer am 13 Jul. 2021
Kommentiert: Peter Beringer am 13 Jul. 2021
Hi,
I wish to represent a 3D array of reciever positions as dots - see attached plot for the general idea (I won't share the shameful code used to generate it, haha). My intention is to then animate the plot by representing each position's signal amplitude by its corresponding dot's colour (each sample generates a new plot/frame). I've successfully animated plots of a 2D plane of receiever positions, with amplitude on Z-axis, so I'll cross any issues with that bridge once I've had a good attempt myself, but I welcome any quick tips or relevant docs people may have about sending the time dimension data to the figure's colour info.
My only question at this stage is actually about how to most effieciently plot a 3D "block" of dots (as below) according to specified dimensions - basically - in very broad terms - to input 3 x 3 x 3 and get something resembling the attached image (or any three dimensions for that matter). The solution is almost guaranteed to be embarassingly simple, but it has eluded me so far (I've been ill, so my concentration is totally shot, which hasn't helped).
Cheers!
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Max Heiken am 13 Jul. 2021
I think you are looking for meshgrid.
[y, x, z] = meshgrid(1:3, 1:3, 1:3);
scatter3(x(:), y(:), z(:), [], amplitude(:), 'o', 'filled');
Notice that it is [y, x, z] and not [x, y, z], it is a quirk of the meshgrid function.
##### 2 KommentareKeine anzeigenKeine ausblenden
Max Heiken am 13 Jul. 2021
Assuming the amplitude is stored with time in the 4th dimension
amplitude = rand(3,3,3,n);
then the animation (in the same figure in this case) could be achieved by something like
h=scatter3(x(:),y(:),z(:),[],reshape(amplitude(:,:,:,1),1,[]),'o','filled');
for epoch=2:size(amplitude,4)
set(h, 'CData', reshape(amplitude(:,:,:,epoch),1,[]));
pause(0.1)
end
Peter Beringer am 13 Jul. 2021
Thank you very much for such an elegant solution. The very obvious thing that was eluding me and causing puzzling errors was that I was not calling the output for 'z' as well as 'x' and 'y' when using 'meshgrid' ... oh, dear, stuck in Edwin Abbott's "Flatland". ;)
In reality, the recordings made at receiver positions will have time/amplitude in the first dimension, but that would only involve a simple permute. Measurements are going to be taken by a linear reciever array moving in lateral increments at each vertical increment, with the recording repeated at each position, so the data will also need concatenating into matrices.
Many thanks again for the help. It might make quite an interesting plot - not unlike early radio telescope array data. Haha.
Cheers!

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Chunru am 13 Jul. 2021
Try scatter3:
t = 0:pi/5:4*pi;
xt = sin(t);
yt = cos(t);
h = scatter3(xt,yt,t,40, t*30, 'MarkerFaceColor', 'b');
colormap(hsv(512))
colorbar
box on
grid on
caxis([0 512])
% Animation
for i=1:20
h.CData = rand(size(t)) * 512;
drawnow
pause(0.1);
end
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Chunru am 13 Jul. 2021
The OP plot can be produced by plot3 as well :-)
Peter Beringer am 13 Jul. 2021
This is another great solution. Might have to use 'tic'/'toc' and race the two. ;)
Many thanks.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by