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

32 次查看(过去 30 天)
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

采纳的回答

José-Luis
José-Luis 2014-6-16
编辑:José-Luis 2014-6-16
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 个评论
José-Luis
José-Luis 2014-6-16
No worries. When in doubt the documentation is a good place to start. It is generally (but not always) well-written.

请先登录,再进行评论。

更多回答(1 个)

Joseph Cheng
Joseph Cheng 2014-6-16
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

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by