MATLAB: Confusing Contour and Color Scale Map Results

In summary, there is a discussion about using MATLAB to draw contour and color scale maps of an array. The results from using the contour and image functions are very different, and it is suggested to normalize the data or use the imagesc() function to get more accurate results. It is also mentioned that the y-axis may need to be reversed in some cases.
  • #1
nenyan
67
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: 389
  • le.jpg
    le.jpg
    6.9 KB · Views: 347
  • b.zip
    40.2 KB · Views: 158
Physics news on Phys.org
  • #2
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: 403
  • #3
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: 368
  • le.jpg
    le.jpg
    17.5 KB · Views: 369
  • #4
Oh, I got it. The y-axis is reversed.
 
  • #5
You can use the imagesc() function instead of normalization. It will automatically set the scale range to the range of your data.
 

1. What is the difference between contour and color scale maps in MATLAB?

Contour maps in MATLAB display a set of lines that connect points with the same data value, while color scale maps use a color gradient to represent the data values. Contour maps are useful for visualizing changes in data values along the lines, while color scale maps are better for understanding overall patterns and trends in the data.

2. Why do my contour and color scale maps in MATLAB look different?

This is because contour and color scale maps display the data in different ways. Contour maps use lines to represent data values, while color scale maps use a color gradient. As a result, the same data may appear differently on these two types of maps.

3. How can I change the color scale on my MATLAB contour map?

To change the color scale on a contour map, you can use the "colormap" function in MATLAB. This allows you to choose a different color scheme or customize the colors and their corresponding data values.

4. Why are my contour lines overlapping on my MATLAB plot?

This can happen if your data has a high level of variation and the default number of contour lines is not enough to show all the different values. You can adjust the number of contour lines or use the "clabel" function to label specific contour lines.

5. Can I create contour maps with a logarithmic scale in MATLAB?

Yes, MATLAB allows you to create contour maps with a logarithmic scale by using the "contourf" function. This allows you to visualize data with a wide range of values more effectively.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
572
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top