arrayfun for Create transform object

1 visualizzazione (ultimi 30 giorni)
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]"

Risposta accettata

Satoshi Kobayashi
Satoshi Kobayashi il 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]);

Più risposte (0)

Categorie

Scopri di più su Object Containers in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by