# Generating 4D Plots in Matlab

I have some data in the form of:

       X  Y  Z    Amplitude
0  0  0    0.00
1  0  0    0.00
2  0  0    0.00
3  0  0    0.00
...
27 30  8    0.25
28 30  8    0.25
29 30  8    0.25
30 30  8    0.25


and I want to show them in a 3D plot, with Amplitude either shown in color or with isosurface shapes. The number of elements in each vector exceeds 8000, so I cannot use meshgrid command (results in insufficient memory error).

• Does it have to be Matlab? For large 3d datasets, more sophisticated visualization software such as Paraview or VisIt might be called for. As a stopgap measure, you could try to convert X, Y, Z to single or (if they in fact are, as in your example) int before calling meshgrid. – Christian Clason Jul 25 '16 at 17:24
• ... which, as Matlab informs me, would still take about 950Gbyte memory. You should either subsample before plotting (I doubt such a high resolution is actually useful on a standard monitor -- 8000x8000x8000 is more than 500 billion points) or use a different software (or both). – Christian Clason Jul 25 '16 at 17:33

## 2 Answers

Since you have only 8 slices along the z, it's not unreasonable to make it an animation slicing through z (x-y plot for z=0, then for z=1, ...).

Even if you try to make the 4D plot, likely you won't be able to see much beyond the front. You can use transparencies, but it still won't be possible to view the middle. So you can plot around the outside. So instead of a full meshgrid, you can plot the outside edges of the box with color + a little bit of transparency, and then the first two rows inward. That should save a lot of memory and may be able to fit.

Or try to get some time on an HPC's large memory node. Some of the ones on XSEDE are made with visualization in mind. You may be able to get some time via the Comet trial allocations.

I use matVTK to do this type of volume plotting.

https://www.cir.meduniwien.ac.at/assets/people/birngruber/publications/matVTK_miccai_2009.pdf