Programmatically select a specific object when switching on plotedit

조회 수: 18 (최근 30일)
Csaba
Csaba 2018년 5월 16일
편집: Csaba 2018년 5월 16일
Is there any way to select an object when issuing the command
plotedit(hfig,'on');
I tried to overwrite 'CurrentObject' property but it did not work. There is also a 'CurrentAxes' property, and that did not work either.
Is there any solution?
  댓글 수: 4
Walter Roberson
Walter Roberson 2018년 5월 16일
In what respect would you like it to be selected?
Csaba
Csaba 2018년 5월 16일
편집: Csaba 2018년 5월 16일
When you issue plotedit one of the objects on the figure is selected (selection marks are around the object). The object is usually the one which was last selected in previous use of plotedit. I want to say in advance which object should be selected (I know of course the handles of all objects).

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

채택된 답변

Csaba
Csaba 2018년 5월 16일
편집: Csaba 2018년 5월 16일
OK. Sorry folks, I have found it.
In the defining function:
f=figure;
object=uicontrol(.........,'ButtonDownFcn',{@ButtonDownFcn_Callback,f},'NextPlot','replacechildren',....)
% do it for all objects you define (or you want to select this way)
NextPlot property is necessary only for axes.
and the callback function should do:
function ButtonDownFcn_Callback(hObject,eventdata,hfig)
% hfig=figure; handle to figure containing the objects
% find all axes objects
hhh=findobj(hfig,'Type','axes');
%unselect all objects
[NN,~]=size(hhh);
for i=1:NN
hhh(i).Selected='off';
end
% select the currentobject
hfig.CurrentObject.Selected='on';
plotedit on;
% the object you clicked on will only be selected.
end
and voila, it works.
Note, that plotedit should be switched off in order to use callback again!

추가 답변 (2개)

Fangjun Jiang
Fangjun Jiang 2018년 5월 16일
f=figure(1);
p=plot(1:10);
ax=findobj(f,'type','axes');
  댓글 수: 6
Fangjun Jiang
Fangjun Jiang 2018년 5월 16일
I think "CurrentObject" is read-only. You can't select an object by setting "CurrentObject".
From the document:
CurrentObject — Most recently selected component in figure object
Most recently selected component in the Figure, specified as an object. MATLAB sets the CurrentObject property to the last object the user clicked. This object is the front-most object in the view. You can use this property to determine which object a user has selected.
An object’s HitTest property controls whether that object can become the CurrentObject.
Clicking an object whose HandleVisibility property is off (such as axis labels and title) causes the CurrentObject property to be set to empty. To avoid returning an empty value when users click a hidden object, set HitTest property of the hidden object to 'off'.
Moving the cursor over objects does not update the CurrentObject. Users must click objects to update this property. See the CurrentPoint property for related information.
If you are looking for a quick way to access the current object, consider using the gco command.
Csaba
Csaba 2018년 5월 16일
Yes, I said it does not work. But help does not say it is read-only. So I tried.

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


Sean de Wolski
Sean de Wolski 2018년 5월 16일
Are you perhaps looking for inspect?
inspect(axes)
Note, this has gotten a lot better in 18a.

카테고리

Help CenterFile Exchange에서 Graphics Object Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by