Calling a plotting function inside a loop.
1 view (last 30 days)
Show older comments
Hello all. I'm trying to make a series of figures using a for loop. I need to do a good deal of processing on the points so I'm using my own function to generate the points for each given set of coefficients then convert from spherical to Cartesian coordinates and plot. The relevant code is as follows:
%The matrices dataexist and resultsmatrix are calculated earlier
c = 1;
for d = 1:26
if dataexist(d,c) == 1
figure(d)
coeffs = resultsmatrix(d,:,c);
plotsurface(coeffs);
end
end
function [] = plotsurface(coeffs)
%Cartesian points are calculated based on the coefficients
tri = delaunay(cart(:,1), cart(:,2));
[r,c] = size(tri);
trisurf(tri, cart(:,1), cart(:,2), cart(:,3));
The problem is, this gives me the first surface just fine on Figure 1, but every figure after that is blank. So somehow the function isn't plotting to it's proper figure. I'm wondering if maybe it's all overwriting onto Figure 1 despite my making a new figure before each call to plotsurface but I don't know why it would do that.
0 Comments
Answers (1)
Walter Roberson
on 14 Nov 2011
Create an axes within the figure, pass the axes handle down to plotsurface(), and parent your trisurf() against that particular axes by using the 'Parent' property:
thisaxes = axes('Parent',d);
coeffs = resultsmatrix(d,:,c);
plotsurface(coeffs, thisaxes);
function [] = plotsurface(coeffs, thisaxes)
[...]
trisurf(tri, cart(:,1), cart(:,2), cart(:,3), 'Parent', thisaxes);
4 Comments
Walter Roberson
on 15 Nov 2011
I have verified that with 2008b, trisurf() will first obey any 'Parent' parameter passed in, provided the parent is given as an axis; if no parent is passed in, then it will use gcf to find the current figure, and gca() that to find the current axes on the current figure, and will use that. If for some reason no figure is current, then figure() should be invoked, which will generally return the lowest positive-integer-numbered unused figure.
See Also
Categories
Find more on Surfaces, Volumes, and Polygons 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!