Is there any way of producing a 4d plot from a matrix which has 4 columns (coordinates + value)?

1 view (last 30 days)
I'm trying to produce a volume plot from a matrix that has 4 columns: x_coordinate, y_coordinate, z_coordinate and the value of the variable I'm working with.
It's something like this, assuming that my volume is 3x3x3:
x | y | z | value
0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
0 1 2
0 2 0
0 2 1
0 2 2
1 0 0
1 0 1
1 0 2
1 1 0
1 1 1
1 1 2
1 2 0
1 2 1
1 2 2
2 0 0
2 0 1
2 0 2
2 1 0
2 1 1
2 1 2
2 2 0
2 2 1
2 2 2
At this moment, I'm trying to use 'surf' to do that, but I don't have any idea of how to build my code to convert the coordinates system I have into vectors that can be used without losing my 'value' information. I wanted to know if there's any function that can deal with information organized this way or maybe some simple idea of how to build the code.
Thanks, David

Answers (1)

W. Owen Brimijoin
W. Owen Brimijoin on 22 Jul 2014
It's generally difficult to provide an intuitive graphical representation of high dimensional data. But, and mind you I say this without seeing your dataset, you could try using:
scatter3(x,y,z,S,'filled')
Where S (the size of the markers) is the vector of values* from your fourth column. This will result in a 3D grid of points of different sizes, so you could rotate this plot and see regions in your 3D space that had larger values associated with them.
. .
*You will probably need S to actually be some function of those values, because I believe the units in S are specified as number of pixels, rather than in axis coordinates.
  2 Comments
David Vicente
David Vicente on 22 Jul 2014
I'm assuming you're telling me to use each column as an input vector for the 'scatter3'.
I tried and I get the following error:
scatter3(data(:,1),data(:,2),data(:,3),data(:,4),'filled')
Error using patch
Value must be finite and greater than zero
Error in specgraph.scattergroup/refresh (line 136)
p = patch('Parent',double(this),...
Error in specgraph.scattergroup/schema>LdoDirtyAction (line 145)
refresh(h);
Warning: Error occurred while evaluating listener callback.
> In scatter3 at 90
The data I'm working with was obtained with the use of other software. I have a comma separated .txt file that I load to Matlab, so I can't define my values as a function.
I think what I might need is to convert this 2D matrix to a 3D matrix in which each entry corresponds to a voxel and has a 'value' from the fourth column.
W. Owen Brimijoin
W. Owen Brimijoin on 22 Jul 2014
No I simply meant that the numbers in data(:,4) might be negative (which from the error you are getting might be the case), or might have a dynamic range that wouldn't work well for specifying the size of a dot. So you might have to make another variable, say,
dot_sizes = data(:,4) - min(data(:,4)) %getting rid of the -values
scatter3(data(:,1),data(:,2),data(:,3),dot_sizes,'filled')
Then if the resulting dots are either way too big, or way to small you might have to scale them somehow:
scatter3(data(:,1),data(:,2),data(:,3),dot_sizes*scale_value,'filled')
I don't know what your data is like, you might have a value of 10,000 in there somewhere and that'd be a really big dot on a graph.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!