MATLAB: Plotting 4d data (3d+color) with matrix

4dcolorplot

Hi!
I need to plot a 4d plot using matrix.
For example, I have matrix A [x y z c]
A =[8 7 8 4; 8 7 8 2; 8 7 8 1;8 3 7 1; 8 7 4 1; 8 7 7 1; 8 7 7 2; 8 2 7 1; 8 7 3 2].
I've plotted plot A(x y z)
clear;
A =[];
for i=1:size(A,1)
Z( A(i,1),A(i,2) ) = A(i,3);
end
surf(Z)
and need to plot Variable c using color.
For example
if A[c]>=2,
then use green
else use red.
Can anybody help me?
Thanks.

Best Answer

Z = accumarray(A(:,1:2), A(:,3));
C = double( accumarray(A(:,1:2), A(:,4)>=2) );
surf(Z, C, 'edgecolor', 'none');
colormap([1 0 0; 0 1 0]); %red and green