- Return the link object as an output argument from a function and keep it in the base workspace while interacting with the linked objects.
- Make the hlink variable global.
- Store the hlink variable in an object's UserData property or in application data
Linkprop not persisting after changing scope
5 次查看(过去 30 天)
显示 更早的评论
Hi there,
I am building a GUI with two patch plots. I want these two plots to rotate simultaneously, so I wrote a function in which I use linkprop to link their camera rotation. This works but only within the scope of the function. When the scope is changed the plots are no longer linked.
Here you have a code example of the problem. You can check that the rotation link only works within the 'foo' function.
a = 1;
foo();
b = 2;
function foo()
figure
ax1 = subplot(2,1,1);
[X1,Y1,Z1] = peaks;
surf(X1,Y1,Z1)
ax2 = subplot(2,1,2);
[X2,Y2,Z2] = peaks(10);
surf(X2,Y2,Z2)
hlink = linkprop([ax1,ax2],{'CameraPosition','CameraUpVector'});
rotate3d on
end
My question is then if it is possible to make 'linkprop' persist after changing the scope or if there is another alternative.
Cheers, Guillermo
0 个评论
回答(1 个)
Peter
2019-12-23
Making sure the hlink object is available outside the scope of your function foo by making it an output argument probably solves your problem. it worked for me:
About Link Objects
The link object that linkprop returns stores the mechanism that links the properties of different graphics objects. Therefore, the link object must exist within the context where you want property linking to occur (such as in the base workspace if users are to interact with the objects from the command line or figure tools).
The following list describes ways to maintain a reference to the link object.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!