Multiple surface plots on a single figure

5 views (last 30 days)
B K
B K on 29 Jan 2012
I am trying to make several figures with multiple surface plots on each. Not using subplot or anything, just a bunch of different-colored shells overlapping each other on one figure. What I've been trying to work with is:
for c = 1:figum
figure(c)
resolution = 50;
theta = linspace(1.7, 2.6, res);
phi = linspace(-.1, 0.8, res);
[theta, phi] = meshgrid(theta, phi);
hold on
for c = 1:10
%Calculate r values based on model parameters
[x, y, z] = sph2cart(theta, phi, r);
surf(x,y,z,(ones(size(x))*c))
end
hold off
legend('1','2','3','4','5','6','7','8','9','10')
end
But all I'm getting from this is Figure 1 with the tenth surface for the last figure, and then blank figure windows for the higher numbered figures in the loop. Any ideas why it seems to be skipping my hold on commands AND my new figure commands and just overwriting everything on the first figure?
Thanks in advance!

Answers (1)

Walter Roberson
Walter Roberson on 30 Jan 2012
Perhaps you want figure(c) instead of figure(fignum), since fignum is a constant?
  1 Comment
B K
B K on 30 Jan 2012
Using the constant was an accidental side effect of my condensing two function's worth of material into a quick form to post on here. The real code is advancing in the loop properly.
I tried doing what you suggested, so what I basically do is
for c = 1:fignum
f = figure();
ax = axes('Parent',f);
plotsurface(ax)
end
Where plotsurface then uses
hold on
for c = 1:10
surf(ax, x, y, z, (ones(size(x))*c)
end
hold off
But I'm still getting the same issue, several blank figures and Figure 1 having the shape number 10 in it with nothing else, even though the legend indicates there should be all 10 shapes.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!