MATLAB Answers

# How to decide if a plot is surf or mesh based on graphics handle data?

5 ビュー (過去 30 日間)
dm 2011 年 5 月 9 日
Lets say I have a 3D plot which I want to export to another format, can I in any way tell if the plot is a surface, or a mesh by analyzing the result of get(gca)/get(gcf)/get(handle)?
With
x = -3:0.1:3;
y = -3:0.1:3;
[X Y] = meshgrid(x,y);
R = sqrt(X.^2+Y.^2);
Z = R;
figure
h1 = mesh(X,Y,Z);
a1 = get(gca);
f1 = get(gcf);
J1 = get(h1);
figure
h2 = surf(X,Y,Z);
a2 = get(gca);
f2 = get(gcf);
J2 = get(h2);
the only (initial) difference I can find (unless I'm blind) is:
[J1.EdgeColor = 'flat' J2.EdgeColor = [0 0 0]]
[J1.FaceColor = [1 1 1] J2.FaceColor = 'flat']
[J1.FaceLighting = 'none' J2.FaceLighting = 'flat']
[J1.EdgeLighting = 'flat' J2.EdgeLighting = 'none']
At first I thought I could do a check
if isnumeric( faceColor ) && strcmpi( edgeColor, 'flat' )
plotType = 'mesh'
end
the EdgeColor in the example is set to black, thus being numeric, and my test is indeed wrong.
So the big question is, how can I distinguish the two without looking at the plot?
(the purpose is to export the plot to TikZ/PGF using the LaTeX package pgfplots, however, I need to find out whether to use surf or mesh).
best regards, dm

サインインしてコメントする。

### 採用された回答

Daniel Shub 2011 年 5 月 9 日
Both mesh and surf create objects of the surface class. Therefore, they have identical properties (although potentially different values). What this means is that by changing the properties you can convert the object returned by mesh into an object that is identical to the one returned by surf. The pgfplots package has different "classes" for mesh and surf (you cannot turn one into the other).
You need to go through the properties of the MATLAB object and decided, based on their values, if the object needs to be created with mesh or surf from pgfplots. I do not know pgfplots well, but I think the only time you would need to use mesh is if the MATLAB surface FaceColor property is 'None.' A FaceColor of [1, 1, 1] (i.e., white), which I think is still a surf in pgfplots.
##### 1 件のコメント表示非表示 なし
dm 2011 年 5 月 9 日
Thanks for your answer. I think I'll go for
if strcmpi( faceColor, 'none') || ( strcmpi( edgeColor, 'flat' ) && isequal( faceColor, [1 1 1]))
plotType = 'mesh';
else
plotType = 'surf';
end
as strcmpi( edgeColor, 'flat' ) && isequal( faceColor, [1 1 1]) corresponds to the default values for a mesh plot in MATLAB.
I thought all this graphics stuff would be "easy peasy", but there are obviously more details to handle than one would imagine

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!