Matlab\Octave haven't the same result with contourf

a 夏天 提交于 2019-12-13 23:46:54

问题


I have a problem to use contourf in octave.
If I test the following code in octave and matlab, the result is not at all the same. The result with Matlab is good.

A1=[38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100
    38    44    51    58    65    72    79    86    93   100]

B1=[ 1     1     1     1     1     1     1     1     1     1
    12    12    12    12    12    12    12    12    12    12
    23    23    23    23    23    23    23    23    23    23
    34    34    34    34    34    34    34    34    34    34
    45    45    45    45    45    45    45    45    45    45
    56    56    56    56    56    56    56    56    56    56
    67    67    67    67    67    67    67    67    67    67
    78    78    78    78    78    78    78    78    78    78
    89    89    89    89    89    89    89    89    89    89
   100   100   100   100   100   100   100   100   100   100]

C1=[NaN    NaN    NaN    NaN    NaN    NaN    NaN    NaN    NaN    NaN
    NaN    687    585    865   1045   1283   2465   2661   3042    NaN
    NaN    356    390    426    473    519    574    627   1253    NaN
    NaN    330    334    330    377    423    455    502    583    NaN
    NaN    305    314    330    348    369    395    430    458    NaN
    NaN    NaN    299    306    323    345    366    389    420    NaN
    NaN    NaN    294    302    310    323    340    364    396    NaN
    NaN    NaN    NaN    295    301    314    326    345    371    NaN
    NaN    NaN    NaN    NaN    297    306    318    334    351    NaN
    NaN    NaN    NaN    NaN    NaN    NaN    NaN    NaN    345    NaN]

[c,h]=contourf(A1,B1,C1,[200,300,400,500,600])

Can somebody explain why octave provides a different result than expected?


回答1:


This a known bug. With octave 3.8.2 the resulting image is

As explained in comment #2, a workaround is to change the NaN to -inf, in order to close the contours.

Indeed, with

C1(isnan(C1)) = -inf;
[c,h]=contourf(A1,B1,C1,[200,300,400,500,600])

the plot looks better.



来源:https://stackoverflow.com/questions/26488772/matlab-octave-havent-the-same-result-with-contourf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!