Need to make a 4D plot (3D + Colour)

Hi,
I need to make a 3D surface where colour will represent the fourth variable. I know "surf" is SIMILAR to what I need, but that's not quite it. Basically, I have the following variables:
t = [1:m]
y = [1:n]
f = [1:o]
These should be the three Cartesian corodinate axes.
I also have a variable S that is of dimensions m x n x o. I want this to be represented by colour.
So to summarize, I need a graph of the form (t,y,f,S), where the first three variables are vectors of unequal sizes and the final variable is a multidimensional array whose dimensions are determined by the first three.
Thanks in advance. How do I create a

1 Comment

if i am understanding u right, slice should work perfectly for ur application.

Sign in to comment.

Answers (8)

Image Analyst
Image Analyst on 31 Mar 2012
How about scatter3()? You can set the color and size of the data points that are plotted.
But how can you have unequal lengths of your 3 dimensions?

6 Comments

Well, basically, I have a set of time-domain signals that are separated in space, and I have taken the continuous-wavelet transform of them to get a scalogram. Thus, I have three variables as the axes: time (t), space (x), and scales/frequency (a), as well as the actual scalogram itself--or rather, a set of scalograms for each of the different spatially separated signals.
Specifically, the time variable is a vector of length 76050.
The scales variable is a vector of length 100.
The space variable is a vector of length 4.
Thus, the set of scalograms is a multidimensional array of length 100x76050x4, with the actual values inside representing the amplitude.
It's pretty confusing. But I feel like there's a way to do what I need. I'm just not sure scatter3 is it, since I think the vectors need to be of equal lengths.
Thanks anyway, though. I definitely appreciate the suggestion. :)
OK, like I thought. You don't have 3 different lengths for each variable. They're all the same length. You're getting confused with the range of each variable and how many levels it's quantized into with the array that has your data. Look at it this way: you have a variable "time" which is quantized into 76050 levels and it can take any one of those levels. You have "scales" which can take any one of 100 values, and "space" can take any of 4 allowable values. Now, let's say you have 1000 data points. Each one of those data points will have a "time" value, a "scales" value, and a "space
value. If you were to write these down in a list, you'd have
# time, scales, space, value
1 t1 sc1 sp1 value1
2 t2 sc2 sp2 value2
...
1000 t1000 sc1000 sp1000 value1000
This is list of 1000 "time" values, 1000 "scales" values, and 1000 "value" values. 1000 of each of them. If you made this a 3D array of 100x76050x4 like you said, you'd have 30420000 voxels but since you have only 1000 data points, only 1000 of those 30420000 voxels would have a value, the rest being zero or whatever you initialized your numerical array to. Note: it is NOT a 4D array just because you have 4 numbers. You have 3 independent values and a dependent value so that is 3D. Just like a 2D gray scale image is a 2D image because it has a row and column (or y and x) and an intensity value. However if your "value" is actually not a single value, but a triplet of RGB values, then your array would be a 4D array. You specify independently (time, scales, space, colorChannel) and you get out the intensity value for that color channel (e.g. the Red intensity or the Blue intensity). It sounds like you don't have that. It sounds like you have a single value where you want to associate that value with a color so that is a 3D image with a colormap, or a 3D "indexed" image using MATLAB lingo.
Thanks! So,uh, what do I do? Which functions should I use?
Would TriScatteredInterp() work for your visualization?
Possibly. I'm looking into it now. It doesn't seem easy to use, though. The function seems to be more-or-less interchangeable with griddata3. I should summarize where I've come to this point:
First, I read in a set of signals, which are indexed according to space (from 1 to 4). Then, I define a set of scales (a = 1:100), and for each of the signals, I take the continuous wavelet transform using the "wscalogram()" function to yield a matrix of values for each signal: the rows represent time and the columns represent frequency/scales (or possibly vice-versa). These matrices are called sgram1, sgram2, sgram3, and sgram4 (i.e. one for each point in space). The actual values in each entry are the amplitudes. Since I have multiple signals, I index them according to space. I can then concatenate these four matrices into one to yield the multidimensional array "sgram", which is 4x7605x32.
And that's basically where I'm at. I'm also looking into those other programs you suggested in your other comments--hopefully I can easily export data from MATLAB to these programs. I'm also worried about the computations themselves--there's a lot of data to work with (even with very short signals), so the visualization itself is rather slow. =S If I do use these other programs then hopefully that issue should be resolved.
I really appreciate you helping me like this, Image Analyst. Thanks again, so much.
MATLAB says this: "TriScatteredInterp is the recommended alternative to griddata as it is generally more efficient."

Sign in to comment.

I'm curious how slice doesn't fit your needs. I'm no data visualization expert so please take this as an honest "I'd like to know more" question :)
t = 1:100:7650;
scales = 1:10:100;
x = 1:4;
[T,SCALES,X] = meshgrid(t,scales,x);
tslice = [];
scalesslice = [];
xslice = 1:4;
SGRAM = T + SCALES + X;
surfHandles = slice(T,SCALES,X,SGRAM,tslice,scalesslice,xslice);
set(surfHandles,'FaceAlpha',0.4,'EdgeAlpha',0.1)
It can look so pretty...
I've always kinda been interested in 4D visualization, so please let us know whatever solution you find :)

4 Comments

That code is quite helpful! I would have never thought to use something like that. BUT...when I actually put in my data, it gets pretty slow. Also, in your example, all four slices look the same. Finally, I'm not interested necessarily in the slices themselves, but rather an object made from them. So I think the way to proceed is either Amara or Avizo--I just still have to find out exactly how.
Thanks anyway, though! I haven't before used statements like "Variable = []" or "surfHandles = slice()", "set", etc., so I'll definitely keep that in mind for the future. :)
Thanks Mike.
Good luck with those other tools (I've never used them).
Also, since you mentioned you were "interested in an object made from the slices", this makes me think scatter3 is more along the lines of what you want. Here's a concrete example for you (see below). Also, it's nice to have someone as responsive as you've been asking questions :)
%Scaled vectors
t = linspace(-3,3,7650);
scales = linspace(-3,3,100);
x = linspace(-3,3,4);
%Decimate
t = t(1:100:7650);
scales = scales(1:10:100);
x = x(1:4);
%Expand independent vectors into 3 dimensional arrays
[T,SCALES,X] = meshgrid(t,scales,x);
%Calculate some fake data
SGRAM = T.^2 + SCALES.^2 + X.^2;
%Remove data that is not within some threshold
SGRAM(SGRAM > 15) = NaN;
SGRAM(SGRAM < 7) = NaN;
%Perform scatter
scatter3(T(:), SCALES(:), X(:), 5*ones(size(X(:))), SGRAM(:))
grid off
@mike -
Have you checked out isosurface? If you are interested in shapes it may suit your needs
I met the similar problem, and the data is as follows, the four variables of t, y, f, S all are descrete,and the S is determined by t,y,f,how could I plot them in one gragh? Thank you very much!
t y f S
0.0000001 3600 52000000 0.76
0.000001 3600 52000000 0.76
0.00001 3600 52000000 0.76
0.0001 3600 52000000 0.76
0.001 3600 52000000 0.76
0.01 3600 52000000 0.76
0.1 3600 52000000 0.76
1 3600 52000000 0.76
10 3600 52000000 0.77
100 3600 52000000 0.81
400 3600 52000000 0.82
1000 3600 52000000 0.81
10000 3600 52000000 0.80
100000 3600 52000000 0.80
1000000 3600 52000000 0.79
10000000 3600 52000000 0.79
400 0.0000001 52000000 0.58
400 0.000001 52000000 0.58
400 0.00001 52000000 0.58
400 0.0001 52000000 0.58
400 0.001 52000000 0.58
400 0.01 52000000 0.58
400 0.1 52000000 0.57
400 1 52000000 0.55
400 10 52000000 0.64
400 100 52000000 0.76
400 1000 52000000 0.81
400 3600 52000000 0.82
400 10000 52000000 0.81
400 100000 52000000 0.72
400 1000000 52000000 0.66
400 10000000 52000000 0.62
400 3600 0.0000001 0.00
400 3600 0.000001 0.00
400 3600 0.00001 0.00
400 3600 0.0001 0.00
400 3600 0.001 0.00
400 3600 0.01 0.00
400 3600 0.1 0.00
400 3600 1 0.00
400 3600 10 0.00
400 3600 100 0.22
400 3600 1000 0.66
400 3600 10000 0.67
400 3600 100000 0.72
400 3600 1000000 0.78
400 3600 10000000 0.80
400 3600 52000000 0.82

Sign in to comment.

have a look at
slice()

1 Comment

Hmm, it doesn't seem to be what I need. Thanks anyway, though!

Sign in to comment.

Mike
Mike on 1 Apr 2012
I just thought of an idea. What if I scaled the variables appropriately so that their sizes can fit into a function like surf or scatter3D? So currently, the variables are like 32x76050x4. Using linspace or something along those lines, I should be able to make thse guys line up.
Let me give this a try.
Mike
Mike on 1 Apr 2012
To add to my previous thought, I was thinking of using the function decimate() to help me. Basically, the initial "amplitude" is a signal that I read in, so it's not automatically "parameterized", so to speak. It's 76050 samples, and using the sampling rate, I can convert that into seconds. I think I can significantly reduce the size of the signal which will definitely speed up computations and file I/O (though obviously it won't be as detailed), but more importantly, if I use that for the amplitude variable combined with "linspace" for some of the other variables then I might be able to "get the sizes of the inputs to agree"--either to the surf function (unlikely), or scatter3 (more likely). Though I'd prefer the surf, really.
I'm mostly thinking aloud at this point. What do you guys think? Seem like a good idea?
I think you may be able to use SURF to get the 3-D data, (use interpolated 't', 'y', 'f', by using TriScatteredInterp) in SURF and then use the fourth dimension (scale appropriately) to set the 'CData' (Color data property) of the resulting SURF object. This may need to be interpolated as well. You may that way plot the points as appropriate and set color using your dataset pretty much as you wanted. Small example:
nPoints = 20;
t = rand(nPoints, 1);
y = rand(nPoints, 1);
f = rand(nPoints, 1);
clr = rand(nPoints, 1);
% to make it compatible with 'CData', replicate columns to give G, B values
clr = repmat(clr, 1, 3);
scatHand = scatter3(t, y, f);
set(scatHand, 'CData', clr);

1 Comment

But in this example, don't you have t,y, and f all the same size vector? In my case that's not the reality, and so I'm not sure if I can do this. I'll give it a try, though, and let you know the results.
By the way, I crossposted this question to StackOverflow, and they suggested using scatter3:
http://stackoverflow.com/questions/9960456/matlab-need-to-make-a-4d-plot-3d-colour-color
I still have to try that last suggestion as well.
Thank you for your suggestion, though! Again, I will try it out.

Sign in to comment.

Mike
Mike on 1 Apr 2012
I found this thread:
I'm not sure if it's exactly the same thing that I want, though. It kind of sucks to know that MATLAB simply can't do what I want (if it is true--and if so, I wish I knew this before), but I'm downloading Amira now, so hopefully this will help. We'll see.

2 Comments

MATLAB's 3D visualization capabilities are relatively weak. If you want to do true 3D volume visualization, you'll need Amira or Avizo. They're very powerful.
OK, I downloaded the trial versions of both of those programs, and it seems to be working fine, including the integration with MATLAB.
The problem is that I'm not familiar with these programs (which actually seem to be quite similar to each other), so I'm still not sure exactly how to get what I want. Still, I feel like I'm very close to the solution! In my pool right now I have the following variables:
t (1 x 76050 x 1)
scales (1 x 100 x 1)
x (1 x 4 x 1)
sgram1 (100 x 76050 x 1)
sgram2 (100 x 76050 x 1)
sgram3 (100 x 76050 x 1)
sgram4 (100 x 76050 x 1)
sgram (100 x 76050 x 4)
So, I want "t", "x", and "scales" to define the axes and "sgram's" coordinates to be the colour. Basically, the same as before, except I have these powerful new tools under my belt--I'm just not sure how to use them.
Thanks in advance!

Sign in to comment.

Kye Taylor
Kye Taylor on 3 Apr 2012
I take it that the four dimensions are the four different indices you are using to index your signals? If so, why would you treat these as coordinates in space. Typically, energy densities, such as that returned by wscaleogram, are visualized as images. In your case, you would want to look at four different images. What am I missing?
Check out Jarrod Rivituso's code above for an interesting way to display 4 such images.
Furthermore, I would double check how you're arriving at the dimensions 7605x32. (32 is likely scales, not 100, and 7605 is likely the length of your longest signal) No?

2 Comments

Yeah, sorry, I keep going back and forth between 100 scales and 32 scales. For now I am keeping it 32 scales and 7605 time samples (I just truncated it by a factor of 10--with a sampling rate of 480 Hz, it's now about 15 seconds rather than 150), because I need to minimize the amount of data for practical computations.
But yeah, that's basically it. You get a typical scaleogram from wscaleogram, which consists of time on the x-axis and scales on the y-axis, with color representing amplitude. Now I have that, in addition to a spatial dimension to index each individual signal that gets fed into the scaleogram function.
I'll take another look at his code. For now I've been playing around with Avizo, though I'm running into problems here as well due to my unfamiliarity with the software.
I think he has 3 independent variables: time, scale, and space, and one dependent variable: "value of the amplitude" so it's a 3D array. See the first two comments to my answer.

Sign in to comment.

Asked:

on 31 Mar 2012

Commented:

on 18 Jun 2018

Community Treasure Hunt

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

Start Hunting!