fill rectangles with colors

hello ..
i used this instraction to plot rectangles with defrent colors ..i need help to fill those rectangles with colors .>>
thanks for hellllp :)
.plot([posx posx+Element(i).W posx+Element(i).W posx posx],...
[posy posy posy+Element(i).H posy+Element(i).H posy],...
'-','color',cl(i,:))

回答 (3 件)

Sudheer Bhimireddy
Sudheer Bhimireddy 2020 年 8 月 4 日

1 投票

Try this:
With the vertices you have, create surfaces and adjust the Z value to see the overlap. However, this way hides the overlapped regions and shows only the top most surface as shown in the attached image.
h=figure;
surf([0 1;0 1],[0 0;1 1],[1 1;1 1]);
hold on;
surf([0 2;0 2],[0 0;2 2],[1 1;1 1]-0.01);
surf([1.4 1.8;1.4 1.8],[1.4 1.4;1.8 1.8],[1 1;1 1]+0.01);
surf([0.7 1.2;0.7 1.2],[0.7 0.7;1.2 1.2],[1 1;1 1]+0.02);
view([0 90]);
Result:
Hope this helps.

1 件のコメント

ahmed noori
ahmed noori 2020 年 8 月 5 日
thanks ..i ll try it

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

Image Analyst
Image Analyst 2020 年 8 月 4 日

1 投票

Did you try the rectangle() function? It has options for 'FaceColor', and 'EdgeColor'.

3 件のコメント

ahmed noori
ahmed noori 2020 年 8 月 5 日
thanks for answer ...
i tried but this fuction can not gives different colors for rectangles in same loop
Sudheer Bhimireddy
Sudheer Bhimireddy 2020 年 8 月 5 日
If you are using rectangle() inside the loop and have manageable number of them, make sure to alter the 'FaceColor' and 'EdgeColor' properties each time the method is invoked.
% this way you will have more control over coloring them
edge_colors = {'k','r','b','m','g','c'};
face_colors = {'k','r','b','m','g','c'};
h = figure;
clf;
hold on;
for i =1:n
rectangle([ ],[ ],'FaceColor',face_colors{i},'EdgeColors',edge_colors{i});
end
ahmed noori
ahmed noori 2020 年 8 月 5 日
thank you ..it was so useful

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

Image Analyst
Image Analyst 2020 年 8 月 5 日

1 投票

Try this:
numRects = 20;
positions = rand(numRects, 4); % Positions = [x, y, width, height]
% this way you will have more control over coloring them
edge_colors = rand(numRects, 3);
face_colors = rand(numRects, 3);
h = figure;
clf;
hold on;
for k = 1 : numRects
rectangle('Position', positions(k, :), 'FaceColor',face_colors(k, :),'EdgeColor',edge_colors(k, :), 'LineWidth', 2);
end
grid on;

1 件のコメント

ahmed noori
ahmed noori 2020 年 8 月 5 日
that was so useful ... thanks

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

カテゴリ

質問済み:

2020 年 8 月 4 日

コメント済み:

2020 年 8 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by