How can I draw 2 surfaces in one graph?
Show older comments
Hi,
I am trying to create a 3d graph with 2 surfaces as I have 2 sets of 3d data. When i run the programme, the graphs are generated seperately. Please help. Below is the code I used:
function [fitresult, gof] = graph1(a, b, c, d)
[xData, yData, zData] = prepareSurfaceData( a, b, c );
ft = fittype( 'biharmonicinterp' );
opts = fitoptions( ft );
opts.Normalize = 'on';
[fitresult{1}, gof(1)] = fit( [xData, yData], zData, ft, opts );
figure( 'Name', 'surface1' );
h = plot( fitresult{1}, [xData, yData], zData );
xlabel( 'a' );
ylabel( 'b' );
zlabel( 'x' );
grid on
hold on;
[xData, yData, zData] = prepareSurfaceData( a, b, d ),
ft = 'linearinterp';
opts = fitoptions( ft );
opts.Normalize = 'on';
[fitresult{2}, gof(1)] = fit( [xData, yData], zData, ft, opts );
figure( 'Name', 'surface2' );
h = plot( fitresult{2}, [xData, yData], zData );
xlabel( 'a' );
ylabel( 'b' );
zlabel( 'x' );
grid on
Thank you.
3 Comments
You don't seem to be plotting any surfaces only line plots, but you have these two lines:
figure( 'Name', 'surface1' );
...
figure( 'Name', 'surface2' );
so of course your plots will be on separate figures, you are very explicitly telling it to create those 2 figures. The plot function can take an axes handle as the first argument so just create the axes you want and give its handle to the plot functions and use e.g.
hold( hAxes, 'on' )
to ensure that the 2nd plot does not replace the first, where hAxes is your axes handle.
Tina
on 16 Jun 2017
Adam is right. If you use "figure(...)" again after "hold on;", it will ignore the "hold on" and generate a new plot.
Vijal Gala
on 16 Jun 2017
Answers (0)
Categories
Find more on Surface and Mesh Plots 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!