How to replace a rectangle with another rectangle?
1 回表示 (過去 30 日間)
古いコメントを表示
(Or change the properties of the first rectangle)
I had 2 ideas of how to replace the rectangle, but both don't work. But here they are:
Idea 1:
r = findobj('FaceColor', [0.2 0.2 0.7])
r.FaceColor = [0.2 0.2 0.2]
Idea 2:
r = rectangle(findobj('FaceColor', [0.2 0.2 0.7]))
r.FaceColor = [0.2 0.2 0.2]
Idea 3:
r = findobj('FaceColor', [0.2 0.2 0.7])
rectangle('Position',r.Position,'LineWidth',1, 'FaceColor', [0.2 0.2 0.7])
I think you can't story a rectangle in a variable but I'm not sure and don't know how to do it otherwise. I want to change the facecolor of the rectangle with the facecolor [0.2 0.2 0.7].
2 件のコメント
Walter Roberson
2020 年 1 月 30 日
The form in Idea 1 worked when I tried it, if the goal is to change the color of an existing rectangle without creating a new one.
回答 (1 件)
Ridwan Alam
2020 年 1 月 30 日
編集済み: Ridwan Alam
2020 年 1 月 30 日
I tried this, it worked for me:
r = rectangle('FaceColor', [0.2 0.2 0.7]);
r.FaceColor = [0.2 0.2 0.2];
2 件のコメント
Ridwan Alam
2020 年 1 月 30 日
編集済み: Ridwan Alam
2020 年 1 月 30 日
Even this worked:
r = rectangle('FaceColor', [0.2 0.2 0.7]); % created the rectangle
r1 = findobj('FaceColor', [0.2 0.2 0.7]); % finds the rectangle handle
r1.FaceColor = [0.2 0.2 0.2]; % change rectangle property using handle
Please let me know which part is not working for you.
Btw, if the rectangle doesn't exist, findobj() returns an empty handle.
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!