MATLAB: Confusing Contour and Color Scale Map Results

  • Context: MATLAB 
  • Thread starter Thread starter nenyan
  • Start date Start date
  • Tags Tags
    Confusing Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 2K views
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

  • ri.jpg
    ri.jpg
    8.7 KB · Views: 471
  • le.jpg
    le.jpg
    6.9 KB · Views: 428
  • b.zip
    b.zip
    40.2 KB · Views: 243
Physics news on Phys.org
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

  • phys - 12 06 20 matlab image 01.JPG
    phys - 12 06 20 matlab image 01.JPG
    23.8 KB · Views: 472
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

  • ri.jpg
    ri.jpg
    18.1 KB · Views: 451
  • le.jpg
    le.jpg
    17.5 KB · Views: 453
Oh, I got it. The y-axis is reversed.
 
You can use the imagesc() function instead of normalization. It will automatically set the scale range to the range of your data.