MATLAB:在子图中绘制/保存网格函数的 X-Y 视图 [英] MATLAB: Plotting/Saving X-Y views of mesh function in subplots

查看:35
本文介绍了MATLAB:在子图中绘制/保存网格函数的 X-Y 视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我试图将网格函数的 2 变量切片(例如,作为 .jpg)保存为子图.我想使用 .m 文件执行此操作,因为我要生成很多图.我已经想出了如何在他们自己的图形上绘制视图,但我无法让它们正确地绘制为图形中的子图.为了说明我的意思:

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:

以下是各个图的输出:

3D 网格:3D MATLAB 网格图
XY 视图:XY MATLAB 网格视图
YZ 视图:YZ MATLAB 网格视图
XZ 视图:XZ MATLAB 网格视图

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(	au;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(	au;F_d) @ 	au = 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(	au;F_d) @ F_d = 0)');
        title(fname)
    hold off;
    printFig(fid,fnum,slname)
    fnum = fnum+1;

printFig() 只是设置目录信息并执行 print 命令.

printFig() just sets up directory info and does print command.

我的代码设置了两个子图,然后覆盖了网格图的完整 3-d 视图,这不是我想要的.我想在一个图上看到两个视图(XZ 和 YZ).

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.

感谢您的帮助!

-迪伦

根据@Andrew_L 的建议,我在代码中对此进行了修改:

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);

这对另一个子图重复.然而,结果仍然相同.它似乎正确设置了两个空白子图,然后在其上显示完整的伪 3D 图.

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:

%# create axes, and set the view of each
hAx(1) = subplot(221); h = mesh(peaks);   view(3)
hAx(2) = subplot(222); copyobj(h,hAx(2)); view(0,90), title('X-Y')
hAx(3) = subplot(223); copyobj(h,hAx(3)); view(0,0) , title('X-Z')
hAx(4) = subplot(224); copyobj(h,hAx(4)); view(90,0), title('Y-Z')

%# set properties of axes
for i=1:4
    grid(hAx(i), 'on')
    axis(hAx(i), 'tight')
    xlabel(hAx(i), 'Delay (sec)');
    ylabel(hAx(i), 'Doppler (Hz)');
    zlabel(hAx(i), 'Ambiguity function');
end
title(hAx(1), 'Short Tone Ping z(	au;F_d)')
hc = colorbar('Peer',hAx(1));
set(get(hc,'YLabel'), 'String','Magnitude-Squared (dB)')

这篇关于MATLAB:在子图中绘制/保存网格函数的 X-Y 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆