arrayfun for Create transform object

1 visualización (últimos 30 días)
Mohammed Alrashed
Mohammed Alrashed el 13 de Feb. de 2019
Respondida: Satoshi Kobayashi el 13 de Feb. de 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]"

Respuesta aceptada

Satoshi Kobayashi
Satoshi Kobayashi el 13 de Feb. de 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]);

Más respuestas (0)

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by