My rectangle should have a determined color represented by a value

3 ビュー (過去 30 日間)
Philipp Mueller
Philipp Mueller 2016 年 9 月 5 日
コメント済み: Neda 2017 年 11 月 8 日
I have 2 patch objects which should be placed with a determined color (represented by a value). I did not implement it because I dont know how it works. So the rectangle 1 should have the value 50 and the rectangle 2 should have the value 75. The colorbar should start from 0 to 100. Thank you in advance.
v = [0 0; 1 0; 1 1; 0 1;5 5; 10 5;10 10;5 10];%Rectangle 1 and 2
f = [1 2 3 4; 5 6 7 8];
patch('Faces',f,'Vertices',v,'FaceColor','green')
colorbar

採用された回答

Stephen23
Stephen23 2016 年 9 月 5 日
編集済み: Stephen23 2016 年 9 月 5 日
The easiest way is to use caxis, like this:
V = [0,0;1,0;1,1;0,1;5,5;10,5;10,10;5,10];
F = [1,2,3,4;5,6,7,8];
C = [50;75];
patch('Faces',F,'Vertices',V,'FaceVertexCData',C,'FaceColor','flat')
colormap(parula)
colorbar
caxis([0,100]) % set the color limits
which generate this (you can pick whatever colormap suits you best):
TIP: learn that many many operations and functions in MATLAB are designed to be fastest and neatest without using ugly loops. Learn to read the documentation, and how to write efficient code:
  1 件のコメント
Neda
Neda 2017 年 11 月 8 日
How about if we need to change the colour of circle based on their values, and circle superimposed on the image with rectangle which does have 'Curvature',[1 1].

サインインしてコメントする。

その他の回答 (1 件)

Thorsten
Thorsten 2016 年 9 月 5 日
編集済み: Thorsten 2016 年 9 月 5 日
50 and 75 are not valid colorvalues in Matlab. Valid is an RGB triplet in the range [0, 1]. So I assumed that 50 and 75 is an index into a colormap. I choose 'gray', but you can any other valid colormap, like 'parula' or 'jet', for example:
Nfaces = 2;
facecolind = [50 70];
cmap = gray(100);
for i = 1:Nfaces
patch('Faces',f(i,:),'Vertices',v,'FaceColor', cmap(facecolind(i),:))
end
colormap(cmap)
h = colorbar
h.TickLabels = h.Ticks*100
  3 件のコメント
Adam
Adam 2016 年 9 月 5 日
Sounds like you want the jet colourmap then. You could create your own to be more to your taste, but jet does run from blue through green up to red.
Philipp Mueller
Philipp Mueller 2016 年 9 月 5 日
thank you so much

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeBlue についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by