Is there a way to plot a contour with a 3-Dimensional matrix?

33 次查看(过去 30 天)
Hi,
I've asked a lot of questions here recently but I am coming to the business end of my project and the stuff I am trying to do is complex.
I have a 3-D matrix that is 40x180x40, full of scalars. They are all a function of the variables that give it the second two dimensions (so, the 180x40) so it is these values I want on the X and Y axes, and then the colour be determined by the values inside the 3-D matrix. Is this possible?
  8 个评论
Harvey Rael
Harvey Rael 2018-8-4
Yeah I do. X and Y are are dates and times of flight, and the 3-D matrix is fuel cost - I'm trying to plot an interplanetary trajectory. So for example, departing on 01/01/18 and flying for 200 days has a number of fuel costs depending on the variation of another variable. That 3rd variable is significant because it allows me to see all the possible fuel costs, but plotting it isn't as significant. I am trying to plot all the fuel costs for each date and time of flight combination. Does that make sense?
jonas
jonas 2018-8-4
编辑:jonas 2018-8-5
Makes sense! You cannot plot the entire data set on a surface. You can plot a slice of your 3d matrix as a surface, but not the entire data set. I would try scatter3 with color coding, it may end up looking OK.
Start by something like this:
[X Y]=meshgrid(1:40,1:180);
A=randn(40,180,40);
X=repmat(X,1,1,40);
Y=repmat(Y,1,1,40);
scatter3(X(:),Y(:),A(:),[],A(:),'.');
colorbar
As you can see, this blob has a thickness and cannot be represented as a surface.

请先登录,再进行评论。

回答(3 个)

Steven Lord
Steven Lord 2018-8-5
I'm not certain, but from your description I think you might want an isosurface.

Harvey Rael
Harvey Rael 2018-8-7
All have been helpful - I was being stupid. I think I can loop through the third dimension of the matrix, and keep hold on and contour plot that way? My only question arising from that would be - given the filled nature of contourf, would that mean hold on causes each contour plot to sit "on top" of one another, rather than fill it like I want?
  1 个评论
jonas
jonas 2018-8-7
编辑:jonas 2018-8-7
You cannot stack contourf plots, because they are all plotted in the same plane. If you want to make something meaningful of this stack, then you have to adjust the hidden property "ContourZLevel". You will get something like this:
40 stacked plots will make for a colorful but unreadable image :)
See my answer for a better method.

请先登录,再进行评论。


jonas
jonas 2018-8-7
You would probably be interested in using a contourslice plot.

类别

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

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by