How can I use "patch" and "trisurf" at the same time?

11 ビュー (過去 30 日間)
dawaske
dawaske 2016 年 5 月 9 日
回答済み: Matt Cohen 2016 年 5 月 16 日
Hey guys,
I'm currently facing the following problem: I have a 3D grid of data points, each of which are plotted as a small cube in a 3D figure using patch. To better visualize certain regions in the data I now want to add a 3D-surface separating different areas in this figure. I was able to plot such a surface using the "trisurf" function, however, for some reason I couldn't combine those two plots with "hold on" :( Does anyone know what that is and how I can fix it?
Thank you for your help! Daniel
PS: I've been using "patch" and "trisurf" since I don't know any other way to do what I'm planning to do. If you guys know a better way I'm open for it :)

回答 (1 件)

Matt Cohen
Matt Cohen 2016 年 5 月 16 日
Greetings.
I understand that you are interested in plotting both a cubic patch and a triangular surface plot in the same figure.
As mentioned in the documentation for the "trisurf" function, a triangular surface plot in MATLAB is actually just a patch object as well. The order in which you plot each might be affecting the overall result.
Try plotting the triangular surface plot first and then adding the 3D patch cubes to the figure. I have provided some example code below that follows this order to create a surface using "trisurf" and then adds a cubic patch to the figure. I have used the "gca" function to get the current axes, and I am explicitly referencing this axes when creating the cubic patch.
%%First, create a trisurf plot
clear all
clc
close all
[x,y] = meshgrid(1:15,1:15);
tri = delaunay(x,y);
z = peaks(15);
trisurf(tri,x,y,z)
ah = gca;
hold on;
%%Next, add a patch to the current axes
vert = 5*[1 1 -1;
-1 1 -1;
-1 1 1;
1 1 1;
-1 -1 1;
1 -1 1;
1 -1 -1;
-1 -1 -1];
fac = [1 2 3 4;
4 3 5 6;
6 7 8 5;
1 2 8 7;
6 7 1 4;
2 3 5 8];
patch(ah,'Faces',fac,'Vertices',vert,'FaceColor','b');
See if you are able to follow this workflow to successfully add your patches to a figure with an axes containing a triangular surface plot.
I hope this information proves to be helpful.
Matt

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by