Why do contour and image give different results for the same data?

4 replies · 3K views · last reply
nenyan
Messages
67
Reaction score
0
When I use MATLAB to draw contour and color scale map of an array. The result is weird.

my code:
the first:
b=load('c:\...\b.txt');
contour(b)

the second:
b=load('c:\...\b.txt');
image(b)

The results are very different. I upload the array file and two figures.
 
Attachments
  • MATLAB contour plot titled Filter Bank (real), with t (s) from 0 to 120 on the x-axis and f (KHz) from 0 to 1.8 on the y-axis, showing a diagonal band of contour lines sloping downward from about 1.2 KHz near t = 35 s to about 0.75 KHz near t = 78 s.
    ri.jpg
    8.7 KB · Views: 488
  • Mostly uniform dark blue heatmap titled Filter Bank (real), with f (KHz) from about 0 to 250 on the vertical axis and t (s) from 0 to about 32 on the horizontal axis, showing only a faint faint cluster near t = 12 to 14 s and f = 120 to 140 KHz.
    le.jpg
    6.9 KB · Views: 444
  • b.zip
    b.zip
    40.2 KB · Views: 256
nenyan said:
When I use MATLAB to draw contour and color scale map of an array. The result is weird.

my code:
the first:
b=load('c:\...\b.txt');
contour(b)

the second:
b=load('c:\...\b.txt');
image(b)

The results are very different. I upload the array file and two figures.
I'm not a Matlab user, so I'm only guessing from the on-line documentation, but it may be that Matlab's image is treating your flat matrix as levels in the range 0-255 (or 63535). In which case, they are all to small to be distinguishable from 0. Try normalizing the data first - I've attached a Mathcad image (zoomed in slightly) to show what I mean (Mathcad converts reals to integers and shows a similar effect, which the function normalize overcomes)
 
Attachments
  • Mathcad worksheet screenshot showing a 2D scatter plot of data, a 3D surface plot, the normalize(m) formula, and two black grayscale images labelled data and normalize(data), the second showing a faint diagonal white streak.
    phys - 12 06 20 matlab image 01.JPG
    23.8 KB · Views: 489
NemoReally said:
I'm not a Matlab user, so I'm only guessing from the on-line documentation, but it may be that Matlab's image is treating your flat matrix as levels in the range 0-255 (or 63535). In which case, they are all to small to be distinguishable from 0. Try normalizing the data first - I've attached a Mathcad image (zoomed in slightly) to show what I mean (Mathcad converts reals to integers and shows a similar effect, which the function normalize overcomes)

Thank you. After nromalization, it is still different.
 
Attachments
  • MATLAB plot titled Filter Bank (real): contour lines of frequency f in KHz against time t in seconds from 0 to about 130 s, showing a decaying curve from about 1.6 KHz at 25 s to 0.6 KHz, a flat line near 0.55 KHz, and noisy vertical streaks.
    ri.jpg
    18.1 KB · Views: 470
  • Filter bank (real) spectrogram: blue background with colored vertical streaks near 200 kHz and 60 kHz at 250-600 s, plus two curved bright ridges, one near 75 kHz and one rising from 200 kHz at 200 s toward 75 kHz by 1000 s; axes f (KHz) and t (s).
    le.jpg
    17.5 KB · Views: 469
You can use the imagesc() function instead of normalization. It will automatically set the scale range to the range of your data.