arrayfun for Create transform object

2 次查看(过去 30 天)
I need help figuring out how to apply 'Parent' property to hgtransform (transform object ). So each of the circle will have it own transform object: see the MATLAB example :
r = [1;2;1]; x = [-2;0;2]; y = [-2;0;2];
inp = 1:size(r,1); Agent(inp,1) = hgtransform;
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
color = randsample('mcrgbk',inp(end),true);
arrayfun(@(i) patch('XData',xunit(i,:),'YData',yunit(i,:),...
'FaceColor',color(i),'Parent',Agent(i,1)),inp);
daspect([1,1,1]);
the Result:
Agent =
3×1 Transform array:
Transform
Transform
Transform
>> Agent(1)
ans =
Transform with properties:
Children: [3×1 Patch]
Visible: 'on'
HitTest: 'on'
Matrix: [4×4 double]
Show all properties
that is not correct, what I want that each circle will be related to one transform object. So Agent(1) should be "Children: [1×1 Patch]" not "Children: [3×1 Patch]"

采纳的回答

Satoshi Kobayashi
Satoshi Kobayashi 2019-2-13
Agent(inp,1) = hgtransform;
is inappropriate in this case.
r = [1;2;1]; x = [-2;0;2]; y = [-2;0;2];
inp = 1:size(r,1);for i=inp; Agent(i,1) = hgtransform;end;
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
color = randsample('mcrgbk',inp(end),true);
arrayfun(@(i) patch('XData',xunit(i,:),'YData',yunit(i,:),...
'FaceColor',color(i),'Parent',Agent(i,1)),inp);
daspect([1,1,1]);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Object Containers 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by