【问题标题】:MATLAB 3D Plotting of CurvesMATLAB 3D 曲线绘图
【发布时间】:2014-07-07 19:41:13
【问题描述】:

我有 2 个变量要绘制图表,但我不知道要使用哪些函数来获得所需的图表。例如,我有一个变量 Depth,它是一个 70x12 的充满数字的矩阵。 12 代表一年中的每个月。我正在尝试绘制深度与温度的关系图,这也是一个 70x12 的充满数字的矩阵。我这样做的当前方法是在 for 循环中使用 plot3 并在 z 轴上绘制由 1 分隔的每个深度与温度曲线。看起来像这样:

旋转后它看起来像这样:

但是,我想要的是某种网格网格或曲线之间的冲浪,以便我的图表看起来与此类似。我玩过冲浪和网格,但我不知道如何使用我存储在变量中的数据来绘制曲线和通过看起来像这样的曲线的曲面。

【问题讨论】:

    标签: matlab plot mesh surf


    【解决方案1】:

    您可以使用plot3surf 做您想做的事,但强烈建议您使用meshgrid 创建深度和温度以及月份的矩阵。

    以下代码显示了如何执行此操作。我刚刚制作了一些名为temps 的任意温度数据,然后使用meshgrid 将深度和月份的向量转换为与temps 中的每个条目对应的网格。请注意,因为MD 现在是矩阵,所以我不需要for 循环,只需plot3 一次即可。

    % create some data. The problem is that depths and months are vectors while
    % I have a 70x12 grid o temperatures:
    nd = 70;
    depths = linspace(0, 1e3, nd);
    months = 1:12;
    temps = sin((1:nd)'*months/(nd*8));
    
    
    % So make temps and depths matrices too:
    [M, D] = meshgrid(months, depths)
    
    % and now plot:
    figure(112)
    clf
    
    % plot the surface from the matrices returned by meshgrid: notice I used
    % facealpha to change the transparency:
    hs = surf(temps, D, M, 'facealpha', .5);
    hold all;
    
    % now that we used meshgrid we can plot everything at once:
    plot3(temps, D, M, 'linewidth', 3)
    
    view(3)
    grid on
    

    【讨论】:

    • 非常感谢。这帮助我了解了创建冲浪图所需的内容,而没有 for 循环的 plot3 真的很有帮助。我只需要为 Days 创建一个 70x12 矩阵,因为我已经有 12 个相同的深度列。一旦我知道了,我就能够创建一个很好的冲浪图并像你展示的那样绘制所有曲线。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多