As the title says, I'm trying to save the 2-variable slices of a mesh function (as a .jpg, for example) as a subplot. I want to do this using a .m file because I have many plots to generate. I have figured out how to plot the views on their own figures, but I cannot get them to plot properly as subplots within a figure. To illustrate what I mean:
Here are the outputs on individual plots:
3D mesh: 3D MATLAB mesh plot
XY view: XY MATLAB mesh view
YZ view: YZ MATLAB mesh view
XZ view: XZ MATLAB mesh view
And here is my plotting code (not working):
%Ambiguity Surface
fid = figure(fnum);
axes1 = axes('Parent',fid);
view(axes1,[-62.5 28]);
grid(axes1,'on');
hold(axes1,'all');
msh = mesh(taux,fdy,z,'Parent',axes1);
xlabel ('Delay - seconds');
ylabel ('Doppler - Hz');
zlabel ('Ambiguity function (Normalized Magnitude-Squared)');
fname = strcat(name,' (Ambiguity Function z(\tau;F_d))');
title(fname);
cb = colorbar('peer',axes1);
set(get(cb,'ylabel'),'String','Magnitude-Squared (dB)');
hold off;
printFig(fid,fnum,sname)
fnum = fnum + 1;
%Ambiguity Slices
fid = figure(fnum);
hold all;
subplot(2,1,1);
axes1 = axes();
grid(axes1,'on');
view(axes1,[90 0]);
msh = mesh(taux,fdy,z);
xlabel ('Delay - seconds','Visible','off');
ylabel ('Doppler - Hz');
zlabel ('Ambiguity function (Normalized Magnitude-Squared)','Visible','off');
fname = strcat(name,' (Ambiguity Function Slice z(\tau;F_d) @ \tau = 128)');
title(fname)
subplot(2,1,2);
axes2 = axes();
grid(axes2,'on');
view(axes2,[0 0]);
msh = mesh(taux,fdy,z);
xlabel ('Delay - seconds','Visible','off');
ylabel ('Doppler - Hz','Visible','off');
zlabel ('Ambiguity function (Normalized Magnitude-Squared)','Visible','off');
cb = colorbar('peer',axes2);
set(get(cb,'ylabel'),'String','Magnitude-Squared');
fname = strcat(name,' (Ambiguity Function Slice z(\tau;F_d) @ F_d = 0)');
title(fname)
hold off;
printFig(fid,fnum,slname)
fnum = fnum+1;
printFig() just sets up directory info and does print
command.
My code sets up the two subplots and then overlays a full 3-d view of the mesh plot, which is not what I want. I'd like to see two of the views (XZ and YZ) on a single figure.
Thanks for the help!
-Dylan
EDIT: Per @Andrew_L's suggestion, I modified this in my code:
sp1 = subplot(2,1,1);
axes(sp1);
axes1 = axes();
grid(axes1,'on');
view(axes1,[90 0]);
msh = mesh(taux,fdy,z,'Parent',axes1);
This is repeated for the other subplot. The result is still the same, however. It appears to set up the two blank subplots properly and then display the full pseudo-3D plot over it.
Here is a stripped example very similar to what you are trying to achieve:
When you call
axes1 = axes();
right belowsubplot(2,1,1);
, you are settingaxes1
to the default full-window axis when you callaxes()
without any arguments, which is causing the overlap. Instead, try using the handle returned bysubplot
to generate the axes handle. Try the following code for the second section:This (should) at least get everything displayed how you want - I believe that the colorbar scale will not correspond to anything in particular (most likely the number of discrete colors in the bar), so extra code is needed to make sure both plots use the same colormap, and that you change the colormap for the colorbar.