-1

I have two variables say X,Y. X,Y are each5*1 matrices.
Each row represent a particular person and X and Y are two variables that represent two characteristics.
I have combined the effect of X,Y through certain operations to form Z so Z is also a 5*1 matrix.

Now I want to plot X,Y,Z. That is I want to plot (X1,Y1,Z1),(X2,Y2,Z2),...(X5,Y5,Z5)

This is what I did.

[x,y]=meshgrid(X,Y)
z=diag(Z)
surf(x,y,z)

I want to know does this plot points such as (X1,Y2,Z2),(X1,Y3,Z2)(X2,Y1,Z3).
Because I don't want to plot these as I want to plot each individual person and not combining people.

clarkson
  • 561
  • 2
  • 16
  • 32

1 Answers1

0

I'm taking a guess that what you want is a 3d plot of your 5 persons. This will plot the 5 points individually.

plot3(X,Y,Z,'ro')

You can color the values according to the Z values by using scatter3(X,Y,Z,S,C). Where S is representing the size and C the color.

scatter3(X,Y,Z,20,Z)
colormap default

To answer your other question. [x,y]=meshgrid(X,Y) will generate two fields which represent every combination of X and Y. With z = diag(Z) you have a diagonal Matrix. Therefore the points you plot are (X1,Y1,Z1),(X1,Y2,0), ... (X2,Y1,0),(X2,Y2,Z2),(X2,Y3,0) ... So you will plot all posibilities of X and Y but set the Z value to zero if the indexes of Xand Y don't match.

Using surf will then create a plane over these points.

Dennis Klopfer
  • 759
  • 4
  • 17
  • I want a 3d plot using `surf`. I want to see the change of `z` from colors. If I set the `z` value to 0 when `x` and `y ` do not match doesn't it still plot value `0` – clarkson Sep 27 '15 at 10:14
  • I wrote the following function `function f=plotting(x,y,z1) z=zeros(length(x),length(y)); for i=1:length(x) for j=1:length(y) if(i ~=j) z(i,j)=NaN; else z(i,j)=z1(i); end end f=z; end ` Then I used `T=plotting(X,Y,Z) ` `surf(x,y,T)` But it doesn't plot any graph. Is it because it has so many `NaN` values – clarkson Sep 27 '15 at 10:38
  • This happens because `surf` is a function that plots a plane over a grid. The diagonal matrix is no grid, as there are no neighboring elements to the diagonal elements. Can you elaborate how the desired output should look? Edit: you can write `z(~eye(length(x))) = NaN;` to avoid the loops. – Dennis Klopfer Sep 27 '15 at 10:49
  • I edited my post to show you a method to color the individual points. – Dennis Klopfer Sep 27 '15 at 12:51