linkprop objects with hgtransform
linkprop objects with hgtransform
Literately figured out the last problem as soon as I posted. Was able to fix many of the issues I was having. Now the problem revolves around hgtransform
and linkprop
. How does one copy the object location and transformation to additional figures. The code below will copy objects from the first axes
to the next and animate making all of them move. However it doesn't copy the transformation.
hgtransform
linkprop
axes
fig = figure();
% create subplots for stim system 3 plate setup
for aa = 1:3
Stimsubfiguresaa = axes(...
'Position',[((aa*.21)-.2),.2,.2,.2],'color','none');
set(Stimsubfiguresaa,'xLim',[-320,320])
set(Stimsubfiguresaa,'YLim',[-240,240])
set(Stimsubfiguresaa,'Visible','off')
end
axes(Stimsubfigures1);
for aa = 1:10
Xdata = [1+aa*50,10+aa*50,10+aa*50,1+aa*50];
ObjectTransformationaa,1 = hgtransform; % Add object to end of transformation list
ObjectListaa,1 = patch(... % Add object to end of Object list, bind to transformation list
'Parent', ObjectTransformationaa, ...
'XData',Xdata, 'YData',[1,1,20,20],...
'Facecolor', [1,0,0], 'EdgeColor', [1,0,0], ...
'visible','on');
ObjectTransformationaa,1.Matrix = makehgtform('zrotate',50);
NextStepXaa,1 = Xdata;
end
tmp = transpose([ObjectList:]);
tmptrans = transpose([ObjectTransformation:]);
TrialLength = 10;
% copy objects to other figures
copyobj(tmp,Stimsubfigures2)
copyobj(tmp,Stimsubfigures3)
property_names = 'XData', 'YData', 'ZData';
for aa = 1:10
linked_objects = [tmp(aa),...
Stimsubfigures2.Children(aa),...
Stimsubfigures3.Children(aa)];
hlinkaa = linkprop(linked_objects,property_names);
end
timer = tic();
while true
t1 = toc(timer);
if t1 >= TrialLength, break;end % break loop once time trial ends
NextStepX = cellfun(@(x) x+1,NextStepX,'UniformOutput',false);
[tmp.XData] = NextStepX:;
drawnow;
pause(0.1);
step = NextStepX;
end
for aa = 1:3
delete(Stimsubfiguresaa.Children)
end
When I change this section to copy the transformation, the objects transform correctly but lose the animation.
% copy objects to other figures
copyobj(tmptrans,Stimsubfigures2)
copyobj(tmptrans,Stimsubfigures3)
property_names = 'XData', 'YData', 'ZData';
trans_names = 'zrotate';
for aa = 1:10
linked_objects = [tmp(aa),...
Stimsubfigures2.Children(aa),...
Stimsubfigures3.Children(aa)];
Trlink_objects = [tmptrans(aa),...
Stimsubfigures2.Children(aa),...
Stimsubfigures3.Children(aa)];
hlinkaa = linkprop(linked_objects,trans_names);
Trhlinkaa = linkprop(Trlink_objects,trans_names);
end
I tried to perform an copyobj
on both handles but it just results in two sets of objects. How can one link all three together so I can perform rotation change Xdata?
copyobj
1 Answer
1
Figured it out. Will post answer for those who had similar questions.
The hgtransform
is a parent of the objects which are being rotated. because of this when I copy the hgtransform
, the children are also copied, hence why the objects appear in the proper orientation in the other windows. From here, I need to link the children from the copied parents to generate the animation.
hgtransform
hgtransform
% copy objects to other figures
copyobj(tmptrans,Stimsubfigures2)
copyobj(tmptrans,Stimsubfigures3)
property_names = 'XData', 'YData', 'ZData';
for aa = 1:10
linked_objects = [tmptrans(aa).Children(1),...
Stimsubfigures2.Children(aa).Children(1),...
Stimsubfigures3.Children(aa).Children(1)];
hlinkaa = linkprop(linked_objects,trans_names);
end
By replacing the part of code with the section above. One can transform the objects and animate.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.