Color a grid by using an intensity matrix
5 ビュー (過去 30 日間)
古いコメントを表示
Hi all! I need to color a grid according to the values of a specific matrix. In particular, I have a 5x5 matrix representing an intensity value (from 0 to 1) and each value A(i,j) of this matrix is related to a specific cell in the grid. The grid goes from 0 (meters) to 100 (meters)---> 0:20:100 for both axes. Thus, each 20m x 20m cell should have a color according to the matrix described above. I tried with pcolor(), imshow(), imagesc() and so on, but with bad results.
Can you help me? Thanks in advance!!! Giulio (Sapienza University of Rome)
0 件のコメント
採用された回答
Matt Tearle
2011 年 3 月 29 日
What do you mean "bad results"? Can you explain or show what you're doing?
Either way, I'm going to take a guess that the problem is related to the fact that you know the intensities are between 0 and 1, but imagesc always scales to the range of the data. But using image won't work either, because it uses actual values to index into the colormap. If that's the issue, then here are a couple of ways around it:
z = rand(5);
x = 10:20:90;
image(x,x,cat(3,z,z,z))
This makes a 3-D array out of z, then makes a true-color image. Or:
figure
colormap(gray(64))
image(x,x,0.5+z*64), colorbar
which sets the colormap to use 64 colors, then simply expands the possible data range to match that (1 to 64).
0 件のコメント
その他の回答 (4 件)
julio@sapienza
2011 年 3 月 29 日
1 件のコメント
Matt Tearle
2011 年 3 月 29 日
The first problem is easily fixed with "axis xy"
The colormap is irrelevant if you are using a true-color image (which is what my first solution does). By making all three planes of the image equal to z, you make a grayscale image. If you want some other color scheme, you'll have to work out how to make the 3-D array. For example
image(x,x,cat(3,0*z,0.8*z,z))
But it might just be easier to use the second approach I showed.
julio@sapienza
2011 年 3 月 30 日
2 件のコメント
Matt Tearle
2011 年 3 月 30 日
Not a stupid question, but glad you figured it out. For anyone else out there: the point is that image centers the pixels on the axis values, hence the x values have to be the *centers* of the squares, not the edges.
julio@sapienza
2011 年 3 月 31 日
8 件のコメント
Matt Tearle
2011 年 4 月 19 日
mesh(A,'FaceColor','texturemap','EdgeColor','none')
But I'm not sure that's what you're referring to. Can you explain what you'd like to see? Something more like this, perhaps?
bar3(A)
参考
カテゴリ
Help Center および File Exchange で Color and Styling についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!