212 views (last 30 days)

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

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?

Image Analyst
on 2 Apr 2012

Jarrod Rivituso
on 2 Apr 2012

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 :)

Jarrod Rivituso
on 3 Apr 2012

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

bym
on 3 Apr 2012

@mike -

Have you checked out isosurface? If you are interested in shapes it may suit your needs

anysomeday
on 18 Jun 2018

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

Aaditya Kalsi
on 1 Apr 2012

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);

Mike
on 1 Apr 2012

Image Analyst
on 1 Apr 2012

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?

Image Analyst
on 3 Apr 2012

Opportunities for recent engineering grads.

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/34132-need-to-make-a-4d-plot-3d-colour#comment_75980

⋮## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/34132-need-to-make-a-4d-plot-3d-colour#comment_75980

Sign in to comment.