arrayfun for Create transform object
1 view (last 30 days)
Show older comments
Mohammed Alrashed
on 13 Feb 2019
Answered: Satoshi Kobayashi
on 13 Feb 2019
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]"
0 Comments
Accepted Answer
Satoshi Kobayashi
on 13 Feb 2019
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 Comments
More Answers (0)
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!