Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to plot 4D data?

1,652 views
Skip to first unread message

Sean Wilkinson

unread,
Feb 16, 2004, 10:29:36 AM2/16/04
to
i have 2 dimensional ( x and y spatial coordinates)over a z distance
which is a variable too. And every point on this x,y,z coordinates
there exist an intensity value to be plotted. Therefore this
constitute to a 4 dimensional problem. On top of this, i have 4 to 6
similar sets of 4D data to be conbined so that the intensities can be
integrated. How do i do this in Matlab? Need Help...

Thanks

Sean

Guillaume

unread,
Feb 16, 2004, 2:04:34 PM2/16/04
to

Can your brain see this graph? If you can't visualize your graph, it
probably means it can't be done, in or out of Matlab...

If you know what your graph should look like, maybe more details would
be helpful. Is you z really helpful?

Guillaume

Ross Woods

unread,
Feb 16, 2004, 3:39:35 PM2/16/04
to
try help scatter3

Ross

John D'Errico

unread,
Feb 16, 2004, 6:52:58 PM2/16/04
to
In article <itb5lbiwoswl@legacy>,
ps771...@ntu.edu.sg (Sean Wilkinson) wrote:

The approaches I'd use here would be either to:

1. Plot an iso-surface. (Think of this as a 3d
contour plot.)

2. Display patches for the entire volume, where
intensity is used to control the transparancy of
each patch.

Multiple variables can be dealt with using color,
as long as you have no more than 3 outputs.

You may need to use griddatan to interpolate
everything onto a lattice in the 3d space.

HTH,
John D'Errico


--
There are no questions "?" about my real address.

The best material model of a cat is another, or
preferably the same, cat.
A. Rosenblueth, Philosophy of Science, 1945

Andrea

unread,
Feb 17, 2004, 8:19:08 AM2/17/04
to
>>Can your brain see this graph? If you can't visualize your graph,
>>it
>>probably means it can't be done, in or out of Matlab...

Absolutely you can. 4D plots are a very useful things, but it is not
very easy to produce them in Matlab. If the x-y-z data are ordered as
explained in:

http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/chpatch5.shtml

you can easily create 4D plots by filling x-y-z patches with 4th
dimension data. For example:

patch(x,y,z,colors);

will plot the 3D x-y-z grid in which every patch (pseudo-cube cell) is
filled by the color specified in colors. For my applications I had to
do this, and it was fairly complicated to understand (from TMW
manuals) how to organize the x-y-z data to create pseudo-cubix cells.
As example, I had a grid composed by 50820 cells; every cell has 8
corners (24 coordinates), but the software that produced this "grid"
has a different ordering convention wrt Matlab. So this is what I've
done to produce a filled grid in 4D:

% coords is a matrix of size 24x50820

x1 = coords(1:3:end,:);
y1 = coords(2:3:end,:);
z1 = coords(3:3:end,:);

dimensprod = 50820;
xa = zeros(24,dimensprod);
ya = zeros(24,dimensprod);
za = zeros(24,dimensprod);

% Adjust ECLIPSE - Matlab Ordering: X-Direction

xa([1,14,17],:) = repmat(x1(5,:),3,1);
xa([2,5,18],:) = repmat(x1(6,:),3,1);
xa([6,9,19],:) = repmat(x1(8,:),3,1);
xa([10,13,20],:) = repmat(x1(7,:),3,1);
xa([4,15,21],:) = repmat(x1(1,:),3,1);
xa([3,8,22],:) = repmat(x1(2,:),3,1);
xa([11,16,24],:) = repmat(x1(3,:),3,1);
xa([7,12,23],:) = repmat(x1(4,:),3,1);

% Adjust ECLIPSE - Matlab Ordering: Y-Direction

ya([1,14,17],:) = repmat(y1(5,:),3,1);
ya([2,5,18],:) = repmat(y1(6,:),3,1);
ya([6,9,19],:) = repmat(y1(8,:),3,1);
ya([10,13,20],:) = repmat(y1(7,:),3,1);
ya([4,15,21],:) = repmat(y1(1,:),3,1);
ya([3,8,22],:) = repmat(y1(2,:),3,1);
ya([11,16,24],:) = repmat(y1(3,:),3,1);
ya([7,12,23],:) = repmat(y1(4,:),3,1);

% Adjust ECLIPSE - Matlab Ordering: Z-Direction

za([1,14,17],:) = repmat(z1(5,:),3,1);
za([2,5,18],:) = repmat(z1(6,:),3,1);
za([6,9,19],:) = repmat(z1(8,:),3,1);
za([10,13,20],:) = repmat(z1(7,:),3,1);
za([4,15,21],:) = repmat(z1(1,:),3,1);
za([3,8,22],:) = repmat(z1(2,:),3,1);
za([11,16,24],:) = repmat(z1(3,:),3,1);
za([7,12,23],:) = repmat(z1(4,:),3,1);

% Create Patch Faces

xb = reshape(xa,4,6*dimensprod);
yb = reshape(ya,4,6*dimensprod);
zb = reshape(za,4,6*dimensprod);

% Create Faces Colors Based On Cell Porosity

colors = repmat(porosity,1,6)';
colors = colors(:);

% Launch 4D visualizer

figs = figure;
set(figs,'renderer','opengl','backingstore','off');
set(gca,'zdir','reverse','ydir','reverse','drawmode','fast');

% Create Patches

h1 = patch(xb,yb,zb,colors);

set(h1,'edgecolor','w');

% xlabel('X
Coordinates','Color','w','Fontsize',10,'Fontweight','bold');
% ylabel('Y
Coordinates','Color','w','Fontsize',10,'Fontweight','bold');
% zlabel('Z
Coordinates','Color','w','Fontsize',10,'Fontweight','bold');
% grid on
view(3);

axis equal
axis vis3d
axis tight

But even with the OpenGL options, backingstore=off and drawmode=fast,
it is very slow process to visualize the whole grid filled (not
talking about rotating, zooming and so on...). I have a very powerful
PC, and the figure creation process is slow as a turtle. I cannot
imagine on other computers when I will compile my program into an
executable... Compared to other visualization software for 3D-4D
imaging, I was expecting something faster. Perhaps I'm missing
something, but when someone asks for "fast drawing in Matlab", there
are no solutions that can be applied to really have "fast" drawings...

HTH

Andrea.

sean Wilkinson

unread,
Feb 18, 2004, 4:49:43 PM2/18/04
to
thanks for the hints...after thinking...my matrix is in the form of

matrix X contains X coordinates
eg. X(m,n,depth) ....depth contain the number of depth planes.

matrix Y contains Y coordinates
eg. Y(m,n,depth)

matrix Z contains the distance of the depth plane from a reference
point.

eg ..Z(m,n,depth).....if in the first depth plane...the Z value is
2.1.....then the 2D Z is 2.1 2.1 2.1
2.1 2.1 2.1
2.1 2.1 2.1
for the next depth plane..the value may be 5.7 5.7 5.7
5.7 5.7 5.7
5.7 5.7 5.7
All coordinates are unevenly spaced.
The intensity value is the same for all depth planes..eg I(m,n,depth)
for an element.

How do i plot this?
Further more.....this four 3D matrix data correspond to one element
of data. I have 5 other elements of four 3D data to be combined. some
of the coordinates of each element may be the same or close to other
element's coordinates. Intensity value for different elements are not
the same.

The coordinates which are the same or very close to each other for all
element data is my solution of coordinates.


How to represent this in Matlab??

kapil

unread,
Feb 18, 2004, 11:51:57 PM2/18/04
to
hi sean ,

try this

% <<< CODE BEG >>>
% get the data
a=[ 134.341 283.951 339.0 1.0
114.979 293.947 313.0 1.0
96.634 316.549 287.0 4.0
79.374 350.242 261.0 3.0
60.684 362.861 301.0 4.0
43.113 367.384 23.0 2.0];

x=d(:,1);
y=d(:,2);
z=d(:,3);
c=d(:,4);

% create a <stem> plot
h=stem3(x,y,z);
set(h(1),'color',[0 0 0]);
delete(h(2));

% color stem tops appropriately
cs=25;
cm=jet(cs*5);
for i=1:length(c)
line(x(i),y(i),z(i),...
'marker','.',...
'markersize',40,...
'color',cm(cs*c(i),:));
end
% create a suitable <colorbar>
colormap(cm);
ch=colorbar;
set(ch,'ytick',cs*[1:5]);
set(ch,'yticklabel',[1:5]);
set(get(ch,'ylabel'),'string','result');
% <<< CODE END >>>

Not sure how u ll combine it with other sets of ur data though.

THT
kapil

0 new messages