How do I plot multiple XY vectors with corresponding Z values on the same plot?

Hello,
I have recently just started my matlab experience, and have run into a situation that I am having a hard time solving. I have an xls file with with 25 columns (the first on being the X values, and the corresponding 24 being the Y values). I would like to plot the individual 24 XY vectors on the same plot but add a Z element to make it "3D". I can easily plot them all on one graph in 2D, but I'm having trouble figuring out how to add the Z axis in. Here is the code that I am using so far:
%
% clear all
clear all
%%Location of data to analyze
fname='All B columns ROI 94.xls'
%%open data
data=xlsread(fname);
s=size(data);
col=2:s(2)
colA=data(:,1);
X=colA;
Y=data(:,col);
Z=(length(col)); %%I'm assuming this is the problem as it isn't a matrix
figure;
hold on;
plot3(X,Y,Z);
I'm uncertain as to whether I need to recreate the XYZ data into a 3D matrix and then plot it, or if there is a much simpler way of plotting this. I've attached a figure from excel that I was able to make that demonstrates what I would like the plot to look like (it only contains the first three columns of data as an example).
I've done multiple searches and haven't been able to find a solution, so I thought that I'd ask. Any help would be greatly appreciated!
Thanks, Russ

 Respuesta aceptada

José-Luis
José-Luis el 16 de Jun. de 2014
Editada: José-Luis el 16 de Jun. de 2014
IMO, that's not a very good way of presenting data. It might look pretty, but most of the results are hidden. If you really want to do it like that in Matlab, then you could create patch objects and use some transparency.
You could do as follows:
your_data = rand(100,3);
numDat = size(your_data,1);
for y = 1:3;
xx = [1:numDat numDat 1 1]';
yy = y * ones(numDat + 3);
zz = [your_data(:,y); 0; 0; your_data(1,y)];
patch(xx,yy,zz,rand(1,3),'FaceAlpha',0.5,'EdgeColor','none');
end
view(160,50)
But then again, I think simple lines would work much better.
doc plot3

4 comentarios

Thank you so much Jose-Luis!! This worked exactly how I wanted it to!
I know this isn't the best way to plot data, but I'm looking at how the data looks/changes over time (z axis) and this seems to be the best way for just looking at it quickly.
One other question, if I may. How do I get the x axis to show the values from the first column (A) in the xls file instead of the # of data points in column A.
xx = [1:numDat numDat 1 1]';
From what I can figure (again, I know next to nothing in matlab), but it appears to me that the "1:numDat" sets the size and the numbers of the X axis. The actual values go from 0-2.5 (increment of 0.005).
Thanks again!
My pleasure.
Try replacing with:
[0:0.005:2.5 2.5 0 0];
Thanks again! Hopefully one day I'll be able to figure out how matlab works :)
No worries. When in doubt the documentation is a good place to start. It is generally (but not always) well-written.

Iniciar sesión para comentar.

Más respuestas (1)

Here is what you can do to get something along those lines. I'm not sure if there is a function to plot that however what you can do is draw polygons based on the data. See my example:
Y = randi(50,4,100);
X = 1:100;
x = [X X(end:-1:1)];
y = [Y zeros(size(Y))];
z = ones(size(x));
fill3(x,z,y(1,:),'r',x,2*z,y(2,:),'g',x,4*z,y(3,:),'b');axis equal; legend

1 comentario

Thank you for your help and input as well! This also worked and replicated the excel plot exactly.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 16 de Jun. de 2014

Comentada:

el 16 de Jun. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by