-1

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?

ederag
  • 2,409
  • 25
  • 49
Didou139
  • 1
  • 1
  • Did you compare the function descriptions of `contourf` in matlab and octave? Perhaps they should be used in slightly different ways. – Dennis Jaheruddin Oct 21 '14 at 14:13
  • 1
    Well, in Octave it returns an an error: `error: __contour__: subscript indices must be either positive integers less than 2^3 1 or logicals`. It's because you have some `NaN`. You should get rid of them. – am304 Oct 21 '14 at 14:13
  • @am304 With octave 3.8.2 there is no error. What is your version ? – ederag Oct 21 '14 at 17:29
  • 1
    It would be better 1) to include the matlab image in your question, and 2) to provide a fully working code that can be readily copy/pasted. For instance there should be no newline after `A1=`. – ederag Oct 21 '14 at 17:42
  • Question edited. The code can now be copy/pasted – ederag Oct 21 '14 at 18:52
  • @huntj I am using Octave 3.8.0 – am304 Oct 21 '14 at 19:36
  • Octave version in 3.6.4 (Matlab version 2013b) and the plot is the same as mine. The plot with octave can be seen here (http://dl.free.fr/isb8A2MJ7). the sizes of c are different between matlab (2x147) and octave (2x62) The value of h is also different : matlab (1468) , octave (-308.8) – Didou139 Oct 23 '14 at 09:08
  • @Didou139 It would be much better to edit your question and put the image there, rather than a link in a comment. The value of `h` is not relevant. – ederag Nov 01 '14 at 20:35
  • I tried to put the image here but I can't. Sorry – Didou139 Nov 03 '14 at 07:54
  • @Didou139 Use edit, and click on the "image" icon. It seems that you should also read more about how this site works, in the "help" menu. – ederag Nov 09 '14 at 23:57

1 Answers1

0

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

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.

enter image description here

ederag
  • 2,409
  • 25
  • 49