我发布后立刻明白了最后一个问题。能够解决我遇到的许多问题。现在问题围绕着hgtransform
和linkprop
。如何将对象位置和转换复制到其他数字。下面的代码会将对象从第一个axes
复制到下一个fig = figure();
% create subplots for stim system 3 plate setup
for aa = 1:3
Stimsubfigures{aa} = axes(...
'Position',[((aa*.21)-.2),.2,.2,.2],'color','none');
set(Stimsubfigures{aa},'xLim',[-320,320])
set(Stimsubfigures{aa},'YLim',[-240,240])
set(Stimsubfigures{aa},'Visible','off')
end
axes(Stimsubfigures{1});
for aa = 1:10
Xdata = [1+aa*50,10+aa*50,10+aa*50,1+aa*50];
ObjectTransformation{aa,1} = hgtransform; % Add object to end of transformation list
ObjectList{aa,1} = patch(... % Add object to end of Object list, bind to transformation list
'Parent', ObjectTransformation{aa}, ...
'XData',Xdata, 'YData',[1,1,20,20],...
'Facecolor', [1,0,0], 'EdgeColor', [1,0,0], ...
'visible','on');
ObjectTransformation{aa,1}.Matrix = makehgtform('zrotate',50);
NextStepX{aa,1} = Xdata;
end
tmp = transpose([ObjectList{:}]);
tmptrans = transpose([ObjectTransformation{:}]);
TrialLength = 10;
% copy objects to other figures
copyobj(tmp,Stimsubfigures{2})
copyobj(tmp,Stimsubfigures{3})
property_names = {'XData', 'YData', 'ZData'};
for aa = 1:10
linked_objects = [tmp(aa),...
Stimsubfigures{2}.Children(aa),...
Stimsubfigures{3}.Children(aa)];
hlink{aa} = 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(Stimsubfigures{aa}.Children)
end
,然后动画制作所有这些对象。但是它不会复制转换。
% copy objects to other figures
copyobj(tmptrans,Stimsubfigures{2})
copyobj(tmptrans,Stimsubfigures{3})
property_names = {'XData', 'YData', 'ZData'};
trans_names = {'zrotate'};
for aa = 1:10
linked_objects = [tmp(aa),...
Stimsubfigures{2}.Children(aa),...
Stimsubfigures{3}.Children(aa)];
Trlink_objects = [tmptrans(aa),...
Stimsubfigures{2}.Children(aa),...
Stimsubfigures{3}.Children(aa)];
hlink{aa} = linkprop(linked_objects,trans_names);
Trhlink{aa} = linkprop(Trlink_objects,trans_names);
end
当我更改此部分以复制转换时,对象会正确转换但会丢失动画。
copyobj
我试图在两个手柄上执行hgtransform
,但它只会产生两组对象。如何将所有三个链接在一起,以便我可以执行旋转更改Xdata?
弄清楚了。将为那些有类似问题的人发布答案。
hgtransform
是正在旋转的对象的父级。正因为如此,当我复制% copy objects to other figures
copyobj(tmptrans,Stimsubfigures{2})
copyobj(tmptrans,Stimsubfigures{3})
property_names = {'XData', 'YData', 'ZData'};
for aa = 1:10
linked_objects = [tmptrans(aa).Children(1),...
Stimsubfigures{2}.Children(aa).Children(1),...
Stimsubfigures{3}.Children(aa).Children(1)];
hlink{aa} = linkprop(linked_objects,trans_names);
end
时,孩子们也被复制,因此为什么对象在其他窗口中以正确的方向出现。从这里开始,我需要链接来自复制父项的子项以生成动画。
qazxswpoi
用上面的部分替换部分代码。人们可以转换对象和动画。