Borrar filtros
Borrar filtros

Alternative for copyobj function

9 visualizaciones (últimos 30 días)
AYBARS DOGAN
AYBARS DOGAN el 28 de Nov. de 2023
Editada: Walter Roberson el 10 de Dic. de 2023
Hello, I am trying to use app designer. Creating new tab with copyobj function but it seems it cant copy callbacks of objects. Are there any alternative for this function which can copy all the callbacks and properties? Thank you.

Respuestas (1)

Harimurali
Harimurali el 10 de Dic. de 2023
Editada: Walter Roberson el 10 de Dic. de 2023
Hi Aybars,
I understand that you require an alternative to "copyobj" function that can copy all the callbacks and properties of objects.
The 'legacy' option of "copyobj" function can be used to copy all the callbacks and properties of the objects. Here is an example code that shows the working of the 'legacy' option of the "copyobj" function:
ax = axes;
x = randn(100,1);
y = randn(100,1);
s = scatter(x,y,"ButtonDownFcn",@(src,event)displayCoordinates(src,event,ax))
scp = copyobj(s, ax, 'legacy');
function displayCoordinates(src,~,ax)
src.MarkerEdgeColor = rand(1,3);
disp(ax.CurrentPoint(1,1:2))
end
The "scp" scatter plot object has all the properties and callbacks of the "s" scatter plot object.
Few things to note when you are using "copyobj":
  • Any event listeners won’t be copied
  • Any uicontextmenus will not be copied – it will in fact behave strangely due to the fact that it will have the uicontextmenu – but the parent is the original figure – and when you right-click on the object it will change the figure focus.
Hope this helps.

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by