MATLAB MATLAB: Confusing Contour and Color Scale Map Results

  • Thread starter Thread starter nenyan
  • Start date Start date
  • Tags Tags
    Confusing Matlab
AI Thread Summary
Using MATLAB to create contour and color scale maps from an array can yield confusing results due to differences in how functions interpret data. The user experienced discrepancies between the outputs of the contour and image functions, likely caused by the way MATLAB handles matrix values. Normalizing the data was suggested as a potential solution, but it did not resolve the issue. Ultimately, it was identified that the y-axis was reversed, and using the imagesc() function was recommended as it automatically adjusts the scale to the data range. This highlights the importance of understanding function behavior in MATLAB for accurate visual representation.
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: 437
  • le.jpg
    le.jpg
    6.9 KB · Views: 396
  • b.zip
    b.zip
    40.2 KB · Views: 211
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: 442
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: 415
  • le.jpg
    le.jpg
    17.5 KB · Views: 414
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.
 

Similar threads

Replies
4
Views
1K
Replies
32
Views
4K
Replies
3
Views
7K
Replies
1
Views
2K
Replies
2
Views
1K
Replies
5
Views
3K
Back
Top