How to replace a rectangle with another rectangle?

조회 수: 1 (최근 30일)
Kirsten Moons
Kirsten Moons 2020년 1월 29일
편집: Ridwan Alam 2020년 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
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.
Kirsten Moons
Kirsten Moons 2020년 1월 30일
Okay, thank you for your feedback. Then I don't know why it doesn't work for me.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ridwan Alam
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
Kirsten Moons
Kirsten Moons 2020년 1월 30일
I dont know the position of the rectangle, thats why I use findobj.
Ridwan Alam
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 CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by