【问题标题】:Matlab: Creating contour maps/images similiar to SigmaPlotMatlab:创建类似于 SigmaPlot 的等高线图/图像
【发布时间】:2016-06-11 14:43:50
【问题描述】:

如果a = columnsb = rowsc = intensity。如何通过b 创建尺寸为a 的图像,并使每个像素具有c 的强度:

在SigmaPlot中,要创建一个29x4的图像,abc的格式如下,如何在Matlab中对数据进行格式化以达到类似的效果:

[a, b, c] = 

1   1   0
2   1   0
3   1   0
4   1   0
5   1   0
6   1   360.389854270598
7   1   524.553377941978
8   1   587.550618428821
9   1   535.164504523392
10  1   494.350943153525
11  1   509.366595359498
12  1   541.550829317582
13  1   714.122144025010
14  1   807.904727901154 
15  1   634.059149684754
16  1   406.202488197581
17  1   338.349519959103
18  1   348.757723417053
19  1   334.118680593247
20  1   375.846361889047
21  1   507.518116274100
22  1   422.583478997748
23  1   0
24  1   0
25  1   0
26  1   0
27  1   0
28  1   0
29  1   0
1   2   0
2   2   0
3   2   0
4   2   0
5   2   0
6   2   222.769016959765
7   2   426.141970064050
8   2   481.453912764027
9   2   517.069153954465
10  2   487.414455654141
11  2   506.604099604784
12  2   514.770604062499
13  2   460.590220686965
14  2   376.241099616609
15  2   337.728227490832
16  2   394.310238250583
17  2   644.982641646965
18  2   856.664806333676
19  2   1040.69617779231
20  2   1128.07830809176
21  2   1070.24104109274
22  2   850.891638429000
23  2   489.144965506451
24  2   0
25  2   0
26  2   0
27  2   0
28  2   0
29  2   0
1   3   0
2   3   0
3   3   0
4   3   0
5   3   0
6   3   0
7   3   337.875341290982
8   3   446.387817855576
9   3   505.667919278579
10  3   474.666874694826
11  3   404.395323496310
12  3   345.514890319901
13  3   367.942209080407
14  3   450.883569030291
15  3   507.808892555292
16  3   498.203471996257
17  3   501.711478584646
18  3   518.354642382383
19  3   596.694216569632
20  3   591.347390565249
21  3   622.610680837716
22  3   667.944336239558
23  3   445.858691175108
24  3   0
25  3   0
26  3   0
27  3   0
28  3   0
29  3   0
1   4   0
2   4   0
3   4   0
4   4   0
5   4   0
6   4   0
7   4   216.608353008468 
8   4   375.475770667960
9   4   425.565743597413
10  4   380.722854551759
11  4   317.194831801482
12  4   337.830175882681
13  4   352.530658493000
14  4   352.286503054898
15  4   323.117595263304
16  4   289.104540650745
17  4   259.229945714487
18  4   233.527214821773
19  4   137.305656551259
20  4   1418.69232849777
21  4   1055.72415597513
22  4   818.007236956091
23  4   595.146860875435
24  4   363.440841935283
25  4   0
26  4   0
27  4   0
28  4   0
29  4   0

【问题讨论】:

    标签: image matlab contour sigmaplot


    【解决方案1】:

    数据定义好像有不一致:你定义

    • a 作为列(范围从 1 到 29)
    • b 作为行(范围从 1 到 4)
    • 尽管如此,那么您指的是29 x 4 矩阵,而它应该是4 x 29

    其中一部分,您必须首先重新排列输入数据的定义,如下所示:

    abc=[
    1   1   0
    2   1   0
    3   1   0
    4   1   0
    5   1   0
    6   1   360.389854270598
    7   1   524.553377941978
    8   1   587.550618428821
    ...
    all the other data
    ...
    ]
    

    也就是将它们包含在[]中。

    那么你可以:

    • 提取intensity 数据(位于abc 矩阵的第三列中
    • 使用reshape函数将intensity数组转换为矩阵
    • 使用unique函数“自动”获取xy数据
    • 使用length函数获取行数和列数
    • 使用meshgrid 函数生成用于绘制曲面的XY 网格

    此时你可以:

    • 使用surf 函数绘制3D 表面(z 值将是intensity 数据)
    • 创建平面并将intensity 数据用作“颜色”
    • 使用contour 函数绘制二维等高线图
    • 使用contour3 函数绘制3D 等高线图

    此解决方案可以按如下方式实现(其中abc 是您的完整数据集):

    % Get the intensity data
    intensity=abc(:,3);
    % Get the x and y data
    row_data=unique(abc(:,1));
    col_data=unique(abc(:,2));
    n_row=length(row_data);
    n_col=length(col_data);
    
    % Reshape the intensity data to get a 29x4 matrix
    z=reshape(intensity,n_row,n_col);
    % Create the grid to plot the surface
    [X,Y]=meshgrid([1:n_col],[1:n_row])
    
    % Plot a 3D surface
    figure
    surf(X,Y,z)
    shading interp
    colorbar
    
    % Plot a flat surface with 
    figure
    % Create a "dummy" zeros matrix to plot a flat surface
    Z=zeros(size(X));
    surf(X,Y,Z,z)
    shading interp
    colorbar
    
    % Plot a 2D contour
    figure
    [c,h] = contour(z);
    clabel(c,h)
    colorbar
    
    % Plot a 3D contour
    figure
    [c,h] = contour3(z);
    clabel(c,h)
    colorbar
    

    希望这会有所帮助。

    卡普拉'

    【讨论】:

    • 谢谢,这是完美的。有没有办法使用 2d 而不是 3d 图形来绘制平面。另外,如何修改比例尺(添加约束等)
    • 要在“2D”轴上绘制平面,您可以使用图形工具栏中的“旋转工具”手动旋转曲面,也可以使用view function 直接设置视点为view([0 90])。你的第二个问题(关于修改比例尺不清楚,你想达到什么目的?
    • 谢谢,我的意思是我想在比例上设置一个限制,而不是最高值是限制(有时可能是异常情况)。刻度上的最大值由 max(ZData) 设置,我希望用户选择这个值。我希望我很清楚
    • 颜色条比例的限制在坐标区的CLim 属性中设置。您可以更改然后直接设置您的值,例如:set(gca,'clim',[333 1000])
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    相关资源
    最近更新 更多