Update a text object's position used with a movable rectangle.

Quick question,
Lets say i have created a rectangle using
h(i) = imrect(gca, [1,1,4,4]);
and then i add a text object with the rectangles name or some data
text(1,1,num2str(1),'BackgroundColor',[.7 .9 .7],'FontSize',7);
How can i make the text follow the rectangle at its final position after i move it?

 채택된 답변

Walter Roberson
Walter Roberson 2012년 7월 19일

0 개 추천

You might be able to do it by registering a listener on the imrect position, with the callback changing the rectangle position.
There is no standard mechanism for doing this. The closest would be linkprop() but that is for identical property names and meaning; I doubt you want the text() size to be as big as the rectangle.

댓글 수: 3

would something like
nt = text(1,1,num2str(123),'BackgroundColor',[.7 .9 .7],'FontSize',7);
ch = get(nt,'Children');
th = findobj(ch,'Type','text');
headerhand = findobj(th,'String','Two');
set(headerhand,'BackgroundColor',[.7 .1 .6],'FontSize',9)
help. After all there is an endfunction at the rectangle and i store its position every time it moves. I just want the tag to be updated too.
I think i made it work, i use
function numtagUpdate(rawdata,nt,draggedComp)
clmo(nt(draggedComp))
nt(draggedComp) = text(rawdata(draggedComp,1),rawdata(draggedComp,2),num2str(draggedComp),'BackgroundColor',[.7 .9 .7],'FontSize',7);
But after i move it for the second time it sais
Error in numtagUpdate (line 2)
clmo(nt(draggedComp))
I fixed that to, using
nt=function numtagUpdate(rawdata,nt,draggedComp)
Thanks for he help though.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by