필터 지우기
필터 지우기

arrayfun for Create transform object

조회 수: 2 (최근 30일)
Mohammed Alrashed
Mohammed Alrashed 2019년 2월 13일
답변: Satoshi Kobayashi 2019년 2월 13일
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